-
-
Save tarikwaleed/b1848e06668c63e02b2ac748e39c10ff to your computer and use it in GitHub Desktop.
FutureProvider example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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