Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- import 'package:flutter/material.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData.light(),
- debugShowCheckedModeBanner: false,
- home: MyHomePage(title: 'Flutter Demo Home Page'),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- MyHomePage({Key key, this.title}) : super(key: key);
- final String title;
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- int _counter = 0;
- int timerTime = 60;
- int i = 60;
- void _incrementCounter() {
- setState(() {
- var timer = new Timer.periodic(Duration(seconds: 1), callback);{
- };
- });
- }
- int t;
- void callback(Timer timer) {
- if(i == _counter){
- print("End");
- } else {
- print("time is " + t.toString());
- t = i--;
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Center(child: Text("Hedgehog Timer", textAlign: TextAlign.center,style: TextStyle(color: Colors.black)) ),
- backgroundColor: Colors.white,
- elevation: 0.2,
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(
- t.toString(),
- style: TextStyle(fontSize: 150),
- ),
- ],
- ),
- ),
- floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
- floatingActionButton: FloatingActionButton.extended(
- onPressed: _incrementCounter,
- elevation: 4.0,
- icon: Icon(Icons.play_arrow),
- label: Text("Start The Hedgehog Timer"),
- ),
- bottomNavigationBar: BottomAppBar(
- child: new Row(
- mainAxisSize: MainAxisSize.max,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- IconButton(
- icon: Icon(Icons.menu),
- onPressed: () {},
- ),
- IconButton(
- icon: Icon(Icons.more_vert),
- onPressed: () {},
- )
- ],
- ),
- ),// This trailing comma makes auto-formatting nicer for build methods.
- );
- }
- }
Add Comment
Please, Sign In to add comment