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 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
You can’t perform that action at this time.