Skip to content

Instantly share code, notes, and snippets.

@macbroadcast
Forked from mjohnsullivan/quote.dart
Created June 28, 2018 05:58
Show Gist options
  • Select an option

  • Save macbroadcast/72d0c47db30b1e22c97881e4dd37b5e1 to your computer and use it in GitHub Desktop.

Select an option

Save macbroadcast/72d0c47db30b1e22c97881e4dd37b5e1 to your computer and use it in GitHub Desktop.

Revisions

  1. @mjohnsullivan mjohnsullivan created this gist Jun 25, 2018.
    40 changes: 40 additions & 0 deletions quote.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    import 'dart:async';
    import 'dart:convert';

    import 'package:flutter/material.dart';
    import 'package:http/http.dart' as http;

    void main() => runApp(MyApp());

    class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return MaterialApp(
    home: Scaffold(
    body: Quote(),
    ));
    }
    }

    class Quote extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return FutureBuilder(
    future: _getQuote(),
    builder: (context, snapshot) {
    return snapshot.connectionState == ConnectionState.done
    ? Center(
    child: Text(
    snapshot.data,
    textAlign: TextAlign.center,
    ))
    : Center(child: CircularProgressIndicator());
    });
    }
    }

    /// Quote kindly supplied by https://theysaidso.com/api/
    Future<String> _getQuote() async {
    final res = await http.get('http://quotes.rest/qod.json');
    return json.decode(res.body)['contents']['quotes'][0]['quote'];
    }