Skip to content

Instantly share code, notes, and snippets.

@dnys1
Created July 17, 2020 20:54
Show Gist options
  • Save dnys1/daa1b5432e8dbe1e71db7e63010b191c to your computer and use it in GitHub Desktop.
Save dnys1/daa1b5432e8dbe1e71db7e63010b191c to your computer and use it in GitHub Desktop.
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