Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// The action class which handles showing the different actions you can interact with in the timer. Also counts up the counter.
- class Actions extends StatelessWidget {
- AudioPlayer audioPlayer = new AudioPlayer();
- @override
- Widget build(BuildContext context) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: _mapStateToActionButtons(
- timerBloc: BlocProvider.of<TimerBloc>(context),
- counterBloc: BlocProvider.of<CounterBloc>(context),
- spotifyBloc: BlocProvider.of<SpotifyBloc>(context),
- adBloc: BlocProvider.of<AdBloc>(context),
- ),
- );
- }
- List<Widget> _mapStateToActionButtons({
- TimerBloc timerBloc,
- CounterBloc counterBloc,
- SpotifyBloc spotifyBloc,
- AdBloc adBloc,
- BuildContext context,
- }) {
- final TimerState state = timerBloc.currentState;
- if (state is prefix1.Ready) {
- showAd(adBloc);
- return [
- FlatButton(
- child: Text(
- 'START',
- style:
- TextStyle(fontSize: 45.0, color: Color.fromRGBO(252, 3, 3, 1)),
- ),
- onPressed: () => {
- Screen.keepOn(true),
- timerBloc.dispatch(Start(duration: state.duration)),
- spotifyBloc.dispatch(Play())
- },
- ),
- ];
- }
- if (state is Finished) {
- startOver(timerBloc, counterBloc, spotifyBloc, context);
- return [];
- }
- return [];
- }
- // A method that serves as starting over the timer and counting up the counter (Refactor into two methods later).
- void startOver(
- TimerBloc timerBloc, CounterBloc counterBloc, SpotifyBloc spotifyBloc, BuildContext context) {
- if (counterBloc.currentState == (counterBloc.maxSips)) {
- print('TIMER: REACHED MAX LIMIT');
- print('TIMER: REACHED MAX LIMIT');
- return;
- }
- timerBloc.dispatch(Reset());
- timerBloc.dispatch(Start(duration: timerBloc.duration));
- counterBloc.dispatch(CounterEvent.increment);
- spotifyBloc.dispatch(Stop());
- playLocal('iclyd.mp3', spotifyBloc);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement