Skip to content

Instantly share code, notes, and snippets.

@felangel felangel/main.dart
Created May 28, 2019

Embed
What would you like to do?
[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
You can’t perform that action at this time.