Skip to content

Instantly share code, notes, and snippets.

@frank06
Created December 18, 2019 18:37
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 frank06/f85195d247d9854446a4a736d67debf2 to your computer and use it in GitHub Desktop.
Save frank06/f85195d247d9854446a4a736d67debf2 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: Scaffold(body: Center(child: MyWidget()))));
Future<String> callAsyncFetch() => Future.delayed(Duration(seconds: 2), () => "hi");
class MyWidget extends StatelessWidget {
@override
Widget build(context) {
return FutureBuilder<String>(
future: callAsyncFetch(),
builder: (context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return Text(snapshot.data);
} else {
return CircularProgressIndicator();
}
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment