Skip to content

Instantly share code, notes, and snippets.

@felangel
Created May 28, 2019 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felangel/3d25be0d235caf76a3e603c659970f82 to your computer and use it in GitHub Desktop.
Save felangel/3d25be0d235caf76a3e603c659970f82 to your computer and use it in GitHub Desktop.
[flutter_timer] Timer Actions
class Actions extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: _mapStateToActionButtons(
timerBloc: BlocProvider.of<TimerBloc>(context),
),
);
}
List<Widget> _mapStateToActionButtons({
TimerBloc timerBloc,
}) {
final TimerState state = timerBloc.currentState;
if (state is Ready) {
return [
FloatingActionButton(
child: Icon(Icons.play_arrow),
onPressed: () => timerBloc.dispatch(Start(duration: state.duration)),
),
];
}
if (state is Running) {
return [
FloatingActionButton(
child: Icon(Icons.pause),
onPressed: () => timerBloc.dispatch(Pause()),
),
FloatingActionButton(
child: Icon(Icons.replay),
onPressed: () => timerBloc.dispatch(Reset()),
),
];
}
if (state is Paused) {
return [
FloatingActionButton(
child: Icon(Icons.play_arrow),
onPressed: () => timerBloc.dispatch(Resume()),
),
FloatingActionButton(
child: Icon(Icons.replay),
onPressed: () => timerBloc.dispatch(Reset()),
),
];
}
if (state is Finished) {
return [
FloatingActionButton(
child: Icon(Icons.replay),
onPressed: () => timerBloc.dispatch(Reset()),
),
];
}
return [];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment