Created
May 28, 2019 03:01
-
-
Save felangel/f2c23e592a2913d29949fd6e9293fa1d to your computer and use it in GitHub Desktop.
[flutter_timer] Timer Widget
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
class Timer extends StatelessWidget { | |
static const TextStyle timerTextStyle = TextStyle( | |
fontSize: 60, | |
fontWeight: FontWeight.bold, | |
); | |
@override | |
Widget build(BuildContext context) { | |
final TimerBloc _timerBloc = BlocProvider.of<TimerBloc>(context); | |
return Scaffold( | |
appBar: AppBar(title: Text('Flutter Timer')), | |
body: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
Padding( | |
padding: EdgeInsets.symmetric(vertical: 100.0), | |
child: Center( | |
child: BlocBuilder( | |
bloc: _timerBloc, | |
builder: (context, state) { | |
final String minutesStr = ((state.duration / 60) % 60) | |
.floor() | |
.toString() | |
.padLeft(2, '0'); | |
final String secondsStr = | |
(state.duration % 60).floor().toString().padLeft(2, '0'); | |
return Text( | |
'$minutesStr:$secondsStr', | |
style: Timer.timerTextStyle, | |
); | |
}, | |
), | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment