Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4. runApp(new MaterialApp(
  5. onGenerateRoute: (RouteSettings settings) {
  6. if (settings.name == '/') {
  7. return new MaterialPageRoute<Null>(
  8. settings: settings,
  9. builder: (_) => new MyApp(),
  10. maintainState: false,
  11. );
  12. }
  13. return null;
  14. }
  15. ));
  16. }
  17.  
  18. class MyApp extends StatefulWidget {
  19. MyAppState createState() => new MyAppState();
  20. }
  21.  
  22. class MyAppState extends State<MyApp> with TickerProviderStateMixin {
  23. AnimationController _controller;
  24.  
  25. @override
  26. void initState() {
  27. print("initState was called");
  28. _controller = new AnimationController(vsync: this)
  29. ..repeat(min: 0.0, max: 1.0, period: const Duration(seconds: 1))
  30. ..addListener(() {
  31. print('animation value ${_controller.value}');
  32. });
  33. super.initState();
  34. }
  35.  
  36. @override
  37. void dispose() {
  38. print("dispose was called");
  39. _controller.dispose();
  40. super.dispose();
  41. }
  42.  
  43. int _counter = 0;
  44.  
  45. @override
  46. Widget build(BuildContext context) {
  47. return new Scaffold(
  48. appBar: new AppBar(
  49. title: new Text('home screen')
  50. ),
  51. body: new Center(
  52. child: new RaisedButton(
  53. onPressed: () {
  54. setState(() {
  55. _counter++;
  56. });
  57. },
  58. child: new Text('Button pressed $_counter times'),
  59. ),
  60. ),
  61. floatingActionButton: new FloatingActionButton(
  62. child: new Icon(Icons.remove_red_eye),
  63. onPressed: () {
  64. Navigator.push(context, new MaterialPageRoute(
  65. builder: (BuildContext context) {
  66. return new MySecondPage(counter: _counter);
  67. },
  68. ));
  69. },
  70. ),
  71. );
  72. }
  73. }
  74.  
  75. class MySecondPage extends StatelessWidget {
  76. MySecondPage({ this.counter });
  77.  
  78. final int counter;
  79.  
  80. Widget build(BuildContext context) {
  81. return new Scaffold(
  82. appBar: new AppBar(
  83. title: new Text('Certificate of achievement'),
  84. ),
  85. body: new Column(
  86. crossAxisAlignment: CrossAxisAlignment.stretch,
  87. mainAxisAlignment: MainAxisAlignment.spaceAround,
  88. children: [
  89. new Icon(Icons.developer_mode, size: 200.0),
  90. new Text(
  91. 'Congrats, you clicked $counter times.',
  92. style: Theme.of(context).textTheme.title,
  93. textAlign: TextAlign.center,
  94. ),
  95. new Text(
  96. 'All your progress has now been lost.',
  97. style: Theme.of(context).textTheme.subhead,
  98. textAlign: TextAlign.center,
  99. ),
  100. ],
  101. ),
  102. );
  103. }
  104. }
  105.  
  106. @override
  107. void didChangeAppLifecycleState(AppLifecycleState state) {
  108. setState(() {
  109. _notification = state;
  110. });
  111. }
  112.  
  113. switch(state) {
  114. case AppLifecycleState.resumed:
  115. // Handle this case
  116. break;
  117. case AppLifecycleState.inactive:
  118. // Handle this case
  119. break;
  120. case AppLifecycleState.paused:
  121. // Handle this case
  122. break;
  123. case AppLifecycleState.suspending:
  124. // Handle this case
  125. break;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement