Guest User

Untitled

a guest
Dec 10th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import 'dart:async';
  2.  
  3. import 'package:flutter/material.dart';
  4.  
  5. void main() => runApp(MyApp());
  6.  
  7. class MyApp extends StatelessWidget {
  8. // This widget is the root of your application.
  9. @override
  10. Widget build(BuildContext context) {
  11. return MaterialApp(
  12. title: 'Flutter Demo',
  13. theme: ThemeData.light(),
  14. debugShowCheckedModeBanner: false,
  15. home: MyHomePage(title: 'Flutter Demo Home Page'),
  16. );
  17. }
  18. }
  19.  
  20. class MyHomePage extends StatefulWidget {
  21. MyHomePage({Key key, this.title}) : super(key: key);
  22. final String title;
  23.  
  24. @override
  25. _MyHomePageState createState() => _MyHomePageState();
  26. }
  27.  
  28. class _MyHomePageState extends State<MyHomePage> {
  29.  
  30. int _counter = 0;
  31. int timerTime = 60;
  32. int i = 60;
  33. void _incrementCounter() {
  34. setState(() {
  35. var timer = new Timer.periodic(Duration(seconds: 1), callback);{
  36.  
  37. };
  38. });
  39. }
  40.  
  41. int t;
  42. void callback(Timer timer) {
  43.  
  44. if(i == _counter){
  45. print("End");
  46. } else {
  47. print("time is " + t.toString());
  48. t = i--;
  49. }
  50.  
  51. }
  52.  
  53. @override
  54. Widget build(BuildContext context) {
  55. return Scaffold(
  56. appBar: AppBar(
  57. title: Center(child: Text("Hedgehog Timer", textAlign: TextAlign.center,style: TextStyle(color: Colors.black)) ),
  58. backgroundColor: Colors.white,
  59.  
  60. elevation: 0.2,
  61. ),
  62. body: Center(
  63. child: Column(
  64. mainAxisAlignment: MainAxisAlignment.center,
  65. children: <Widget>[
  66. Text(
  67. t.toString(),
  68. style: TextStyle(fontSize: 150),
  69. ),
  70. ],
  71. ),
  72. ),
  73. floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  74. floatingActionButton: FloatingActionButton.extended(
  75. onPressed: _incrementCounter,
  76. elevation: 4.0,
  77. icon: Icon(Icons.play_arrow),
  78. label: Text("Start The Hedgehog Timer"),
  79. ),
  80. bottomNavigationBar: BottomAppBar(
  81. child: new Row(
  82. mainAxisSize: MainAxisSize.max,
  83. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  84. children: <Widget>[
  85. IconButton(
  86. icon: Icon(Icons.menu),
  87. onPressed: () {},
  88. ),
  89. IconButton(
  90. icon: Icon(Icons.more_vert),
  91. onPressed: () {},
  92. )
  93. ],
  94. ),
  95. ),// This trailing comma makes auto-formatting nicer for build methods.
  96. );
  97. }
  98. }
Add Comment
Please, Sign In to add comment