Skip to content

Instantly share code, notes, and snippets.

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 tarikwaleed/b1848e06668c63e02b2ac748e39c10ff to your computer and use it in GitHub Desktop.
Save tarikwaleed/b1848e06668c63e02b2ac748e39c10ff to your computer and use it in GitHub Desktop.
FutureProvider example
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
const appTitle = 'FutureProvider Demo';
return MaterialApp(
title: appTitle,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: FutureProvider<bool>(
initialData: true,
builder: (context) {
// Pretend we're saving data and it takes 4 seconds.
return Future.delayed(Duration(seconds: 4), () => false);
},
child: Scaffold(
appBar: AppBar(
title: Text(appTitle),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Consumer<bool>(
builder: (context, saving, child) {
return Text(saving ? "Saving..." : "Saved!");
},
),
],
),
),
),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment