Skip to content

Instantly share code, notes, and snippets.

@sansal54
Forked from mjohnsullivan/quote.dart
Created December 9, 2019 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansal54/aad8ff5bdf961b1f1f9ce0b5f251702d to your computer and use it in GitHub Desktop.
Save sansal54/aad8ff5bdf961b1f1f9ce0b5f251702d to your computer and use it in GitHub Desktop.
Simple Flutter app to retrieve and display a quote of the day
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'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment