Guest User

Untitled

a guest
Jan 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() async {
  4. runApp(MyApp());
  5.  
  6. while (true) {
  7. print('Do some processing e.g. sync data with server');
  8. const seconds = 3;
  9. print('...sleep for $seconds seconds');
  10. await Future.delayed(const Duration(seconds: seconds));
  11. }
  12. }
  13.  
  14. class MyApp extends StatelessWidget {
  15. // This widget is the root of your application.
  16. @override
  17. Widget build(BuildContext context) {
  18. return MaterialApp(
  19. title: 'Flutter Demo',
  20. theme: ThemeData(
  21. primarySwatch: Colors.blue,
  22. ),
  23. home: MyHomePage(title: 'Flutter Demo Home Page'),
  24. );
  25. }
  26. }
  27.  
  28. class MyHomePage extends StatefulWidget {
  29. MyHomePage({Key key, this.title}) : super(key: key);
  30. final String title;
  31.  
  32. @override
  33. _MyHomePageState createState() => _MyHomePageState();
  34. }
  35.  
  36. class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
  37. int _counter = 0;
  38.  
  39. void _incrementCounter() {
  40. setState(() {
  41. _counter++;
  42. });
  43. }
  44.  
  45. @override
  46. void initState() {
  47. super.initState();
  48. WidgetsBinding.instance.addObserver(this);
  49. }
  50.  
  51. @override
  52. void dispose() {
  53. WidgetsBinding.instance.removeObserver(this);
  54. super.dispose();
  55. }
  56.  
  57. @override
  58. void didChangeAppLifecycleState(AppLifecycleState state) {
  59. super.didChangeAppLifecycleState(state);
  60. print('$state'.toUpperCase());
  61. }
  62.  
  63. @override
  64. Widget build(BuildContext context) {
  65. return Scaffold(
  66. appBar: AppBar(
  67. title: Text(widget.title),
  68. ),
  69. body: Center(
  70. child: Column(
  71. mainAxisAlignment: MainAxisAlignment.center,
  72. children: <Widget>[
  73. Text(
  74. 'You have pushed the button this many times:',
  75. ),
  76. Text(
  77. '$_counter',
  78. style: Theme.of(context).textTheme.display1,
  79. ),
  80. ],
  81. ),
  82. ),
  83. floatingActionButton: FloatingActionButton(
  84. onPressed: _incrementCounter,
  85. tooltip: 'Increment',
  86. child: Icon(Icons.add),
  87. ),
  88. );
  89. }
  90. }
Add Comment
Please, Sign In to add comment