Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Flutter - Async Method Call
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 {
Widget build(context) {
return FutureBuilder<String>(
future: callAsyncFetch(),
builder: (context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return Text(;
} else {
return CircularProgressIndicator();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment