Created
July 17, 2020 20:54
-
-
Save dnys1/daa1b5432e8dbe1e71db7e63010b191c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'package:flutter/material.dart'; | |
void main() { | |
runApp(App()); | |
} | |
class App extends StatefulWidget { | |
App({Key key}) : super(key: key); | |
@override | |
_AppState createState() => _AppState(); | |
} | |
class _AppState extends State<App> { | |
bool _completed = false; | |
@override | |
void initState() { | |
super.initState(); | |
_asyncCallback().then((_) { | |
if (mounted) { | |
setState(() => _completed = true); | |
} | |
}); | |
} | |
Future<void> _asyncCallback() { | |
return Future.delayed(const Duration(seconds: 3)); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: AppBar(title: Text('Async Callbacks')), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text('Completed: $_completed'), | |
if (!_completed) ...const [ | |
SizedBox(height: 10), | |
CircularProgressIndicator(), | |
], | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment