Skip to content

Instantly share code, notes, and snippets.

@collinjackson collinjackson/main.dart
Last active Apr 11, 2019

What would you like to do?
pomodoro timer example
import 'package:flutter/material.dart';
void main() {
runApp(new Container(
color: Colors.white,
runApp(new MaterialApp(
theme: new ThemeData(primarySwatch:,
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(
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),
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,

This comment has been minimized.

Copy link

commented Jan 21, 2018

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


This comment has been minimized.

Copy link

commented Apr 11, 2019

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
You can’t perform that action at this time.