Skip to content

Instantly share code, notes, and snippets.

@collinjackson
Last active December 7, 2019 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save collinjackson/d7dfff892aeb365a28efaac531aa3b4f to your computer and use it in GitHub Desktop.
Save collinjackson/d7dfff892aeb365a28efaac531aa3b4f to your computer and use it in GitHub Desktop.
pomodoro timer example
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),
),
),
);
}
}
@deshaion
Copy link

Please, could you say why from parameter is 0.0 in onPressed here? Why it is not _controller.duration.inSeconds like begin value?

@jagadish906
Copy link

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