You might know that I am currently learning Flutter. I watched few YouTube tutorials, wrote few posts about my learnings, and signed up for the #30DaysOfFlutter. I decided to take my learning journey to the next level by actually implementing something
BrainTrainer is a math game where you have 30 seconds to solve as many questions as possible. Your highest score will be displayed on the app bar and saved in Firebase.
The game has two screens in total. On main.dart we watch the firebase user to determine which screen to display.
ActionButtons Widget: This is where we show the play button to start the game. we also use to indicate to the player if their selected answer is correct or now
GameConfetti Widget: We use this fun widget to display a celebration animation when the play finish the game
import'package:brain_trainer_app/models/game.dart';import'package:confetti/confetti.dart';import'package:flutter/material.dart';import'package:provider/provider.dart';import'package:rflutter_alert/rflutter_alert.dart';classGameConfettiextendsStatefulWidget{@override_GameConfettiStatecreateState()=>_GameConfettiState();}class_GameConfettiStateextendsState<GameConfetti>{ConfettiController_controllerCenter;@overridevoidinitState(){_controllerCenter=ConfettiController(duration:constDuration(seconds:10));_controllerCenter.play();super.initState();}@overridevoiddispose(){_controllerCenter.dispose();super.dispose();}_showAlert(context){Future.delayed(Duration.zero,()async{finalString_gameMsg=Provider.of<Game>(context,listen:false).completionMsg;varalertStyle=AlertStyle(animationType:AnimationType.fromTop,isCloseButton:false,isOverlayTapDismiss:false,descStyle:TextStyle(fontSize:16,fontWeight:FontWeight.bold),descTextAlign:TextAlign.start,animationDuration:Duration(milliseconds:400),overlayColor:Colors.transparent,alertBorder:RoundedRectangleBorder(borderRadius:BorderRadius.circular(0.0),side:BorderSide(color:Colors.grey,),),titleStyle:TextStyle(color:Colors.green,),alertAlignment:Alignment.center,);Alert(style:alertStyle,context:context,type:AlertType.success,title:"Well done",desc:_gameMsg,buttons:[DialogButton(child:Text("Brilliant!!!",style:TextStyle(color:Colors.white,fontSize:16),),onPressed:()=>Navigator.pop(context),width:120,)],).show();});}@overrideWidgetbuild(BuildContextcontext){returnAlign(alignment:Alignment.topCenter,child:ConfettiWidget(confettiController:_controllerCenter,blastDirectionality:BlastDirectionality.explosive,// don't specify a direction, blast randomlyshouldLoop:false,gravity:0.5,emissionFrequency:0.05,numberOfParticles:20,// start again as soon as the animation is finishedcolors:const[Colors.green,Colors.blue,Colors.pink,Colors.orange,Colors.purple],// manually specify the colors to be usedchild:_showAlert(context)),);}}
TimerQuestionScoreRow Widget: Here, we show the 30s timer, The math question, and we keep track of the player score/
Do you enjoy math? Do you enjoy games? Want to relax and train your brain? Try this amazing app for some fun – Brain Trainer.
Brain Trainer consists of simple math-based games designed to exercise memory, speed, and attention. Take a break from your busy schedule and use Brain Trainer to relax and practice some math.