Last active
December 7, 2019 13:42
-
-
Save collinjackson/d7dfff892aeb365a28efaac531aa3b4f to your computer and use it in GitHub Desktop.
pomodoro timer example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(new Container( | |
color: Colors.white, | |
)); | |
runApp(new MaterialApp( | |
theme: new ThemeData(primarySwatch: Colors.red), | |
home: new HomePage(), | |
)); | |
} | |
class PomodoroTimer extends AnimatedWidget { | |
PomodoroTimer({ this.timeRemainingInSeconds }) | |
: super(listenable: timeRemainingInSeconds); | |
Animation<int> timeRemainingInSeconds; | |
Widget build(BuildContext context) { | |
String minutes = '${(timeRemainingInSeconds.value / 60).floor()}'; | |
String seconds = '${(timeRemainingInSeconds.value % 60)}'.padLeft(2, '0'); | |
return new Text( | |
'$minutes:$seconds', | |
style: Theme.of(context).textTheme.display2, | |
); | |
} | |
} | |
class HomePage extends StatefulWidget { | |
HomePageState createState() => new HomePageState(); | |
} | |
class HomePageState extends State<HomePage> with TickerProviderStateMixin { | |
AnimationController _controller; | |
@override void initState() { | |
_controller = new AnimationController( | |
vsync: this, | |
duration: const Duration(minutes: 25), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text('Pomodoro Timer'), | |
), | |
floatingActionButton: new FloatingActionButton( | |
child: new Icon(Icons.play_arrow), | |
onPressed: () { | |
_controller.forward(from: 0.0); | |
}, | |
), | |
body: new Center( | |
child: new PomodoroTimer( | |
timeRemainingInSeconds: new IntTween( | |
begin: _controller.duration.inSeconds, | |
end: 0, | |
).animate(_controller), | |
), | |
), | |
); | |
} | |
} |
If i want to press that button the timer should pause and while clicking again it have to play from remaining time . how i can achieve this
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please, could you say why from parameter is 0.0 in onPressed here? Why it is not _controller.duration.inSeconds like begin value?