Skip to content

Instantly share code, notes, and snippets.

@felangel
Created May 28, 2019 03:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save felangel/7e6e97864bd2d3794deaef410fe50fac to your computer and use it in GitHub Desktop.
[flutter_timer] Timer + Actions
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,
);
},
),
),
),
BlocBuilder(
condition: (previousState, currentState) =>
currentState.runtimeType != previousState.runtimeType,
bloc: _timerBloc,
builder: (context, state) => Actions(),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment