Created
May 28, 2019 03:05
-
-
Save felangel/3d25be0d235caf76a3e603c659970f82 to your computer and use it in GitHub Desktop.
[flutter_timer] Timer Actions
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 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