Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.09 KB | None | 0 0
  1. /// The action class which handles showing the different actions you can interact with in the timer. Also counts up the counter.
  2. class Actions extends StatelessWidget {
  3.   AudioPlayer audioPlayer = new AudioPlayer();
  4.  
  5.   @override
  6.   Widget build(BuildContext context) {
  7.     return Row(
  8.       mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  9.       children: _mapStateToActionButtons(
  10.         timerBloc: BlocProvider.of<TimerBloc>(context),
  11.         counterBloc: BlocProvider.of<CounterBloc>(context),
  12.         spotifyBloc: BlocProvider.of<SpotifyBloc>(context),
  13.         adBloc: BlocProvider.of<AdBloc>(context),
  14.       ),
  15.     );
  16.   }
  17.  
  18.   List<Widget> _mapStateToActionButtons({
  19.     TimerBloc timerBloc,
  20.     CounterBloc counterBloc,
  21.     SpotifyBloc spotifyBloc,
  22.     AdBloc adBloc,
  23.     BuildContext context,
  24.   }) {
  25.     final TimerState state = timerBloc.currentState;
  26.  
  27.     if (state is prefix1.Ready) {
  28.       showAd(adBloc);
  29.       return [
  30.         FlatButton(
  31.           child: Text(
  32.             'START',
  33.             style:
  34.                 TextStyle(fontSize: 45.0, color: Color.fromRGBO(252, 3, 3, 1)),
  35.           ),
  36.           onPressed: () => {
  37.             Screen.keepOn(true),
  38.             timerBloc.dispatch(Start(duration: state.duration)),
  39.             spotifyBloc.dispatch(Play())
  40.           },
  41.         ),
  42.       ];
  43.     }
  44.     if (state is Finished) {
  45.       startOver(timerBloc, counterBloc, spotifyBloc, context);
  46.       return [];
  47.     }
  48.     return [];
  49.   }
  50.  
  51.   // A method that serves as starting over the timer and counting up the counter (Refactor into two methods later).
  52.   void startOver(
  53.       TimerBloc timerBloc, CounterBloc counterBloc, SpotifyBloc spotifyBloc, BuildContext context) {
  54.  
  55.     if (counterBloc.currentState == (counterBloc.maxSips)) {
  56.       print('TIMER: REACHED MAX LIMIT');
  57.       print('TIMER: REACHED MAX LIMIT');
  58.      
  59.       return;
  60.     }
  61.     timerBloc.dispatch(Reset());
  62.     timerBloc.dispatch(Start(duration: timerBloc.duration));
  63.     counterBloc.dispatch(CounterEvent.increment);
  64.     spotifyBloc.dispatch(Stop());
  65.     playLocal('iclyd.mp3', spotifyBloc);
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement