From f534e8c9bcb7805e2e7cfefc6feab745fbd28fee Mon Sep 17 00:00:00 2001 From: Khalid I Date: Wed, 7 Jul 2021 12:07:02 -0500 Subject: [PATCH] lots of fixes --- lib/Maze.dart | 76 +++++++++++++++++++++++++---------------- lib/MazeTest.dart | 66 +++++++++++++++++++++-------------- lib/main.dart | 9 ++--- lib/startingScreen.dart | 13 ++++--- pubspec.lock | 42 +++++++++++++++++++---- pubspec.yaml | 4 +-- 6 files changed, 139 insertions(+), 71 deletions(-) diff --git a/lib/Maze.dart b/lib/Maze.dart index dd333a2..9ad339b 100644 --- a/lib/Maze.dart +++ b/lib/Maze.dart @@ -7,8 +7,8 @@ import 'main.dart'; import 'instructions.dart'; import 'package:uuid/uuid.dart'; import 'userIDD.dart'; -import 'package:audioplayers/audio_cache.dart'; -import 'package:audioplayers/audioplayers.dart'; +import 'package:just_audio/just_audio.dart'; + var uuid = Uuid(); DateTime startTime = DateTime.now(); @@ -76,6 +76,16 @@ class gameButton extends StatefulWidget { class gameButtonState extends State { + //initialize audioplayer + AudioPlayer player; + @override + void initState() { + super.initState(); + player = AudioPlayer(); + } +// stop initializing audioplayer + + Color color; //initialize color state of buttons @@ -115,7 +125,7 @@ class gameButtonState extends State { times=[]; errors = []; consecErrors = 0; - lastMove = 0; //records last CORRECT move of user + lastMove = 0; //records last COR user lastMoveIncorrect = true; clock.reset(); } @@ -142,8 +152,9 @@ class gameButtonState extends State { errors.add("correct"); maze1.button_grid[widget.id].color = Colors.green; maze1.button_grid[widget.id].displayImage = true; - audioCache.play('ding2.mp3'); - icon = Icons.check; + player.setAsset('assets/audio/ding2.mp3'); + player.play(); + icon= Icons.check; Timer(Duration(milliseconds: 75), () { if (this.mounted) { setState(() { @@ -168,6 +179,7 @@ class gameButtonState extends State { "trial": attemptNum.toString() }; String data = json.encode(dict); createData("GMLT-10x10", uuid.v1().toString(), data, "1.0.0"); + player.dispose(); attemptNum++; showDialog( context: context, @@ -176,7 +188,7 @@ class gameButtonState extends State { return AlertDialog( title: new Text("Success!"), actions: [ - new FlatButton( + new TextButton( onPressed: () { resetGame(); Navigator.pop(context); @@ -184,7 +196,7 @@ class gameButtonState extends State { child: new Text("Same Maze") ), - new FlatButton( + new TextButton( onPressed: () { newMaze(); Navigator.pop(context); @@ -205,9 +217,12 @@ class gameButtonState extends State { //keep track of how many consecutive errors user has made- if 3 then game should show next correct move consecErrors++; errors.add("incorrect"); - audioCache.play('buzz2.mp3'); + + maze1.button_grid[widget.id].color = Colors.red; maze1.button_grid[widget.id].displayImage=true; + player.setAsset('assets/audio/buzz2.mp3'); + player.play(); icon = Icons.clear; Timer(Duration(milliseconds: 75), () { if(this.mounted) { @@ -230,16 +245,17 @@ class gameButtonState extends State { Widget build(BuildContext context) { return Container( decoration: BoxDecoration(border: Border.all(color: Colors.black)), - child: FlatButton( - color: maze1.button_grid[widget.id].color, - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + child: TextButton( + style: TextButton.styleFrom( + backgroundColor: maze1.button_grid[widget.id].color, + ), onPressed: () { //what happens on buttonPress event- either nothing (if animation is taking place) or buttonPress function (defined above) called timeOut?null:buttonPress(); }, child: maze1.button_grid[widget.id].displayImage?Column(// Replace with a Row for horizontal icon + text children: [ - maze1.button_grid[widget.id].displayImage?Icon(icon):null, + Expanded(child: maze1.button_grid[widget.id].displayImage?Icon(icon, color:Colors.black):null), ], ):null )); @@ -286,29 +302,31 @@ class mazeState extends State { @override //build and return concrete implemenation of maze class Widget build(BuildContext context) { + //get size of screen //wrapped in notification listener so each square can listen for color change event return NotificationListener( onNotification: updateButton, - child: - Scaffold( + child: Scaffold( backgroundColor: Colors.cyan, body: Column( children: [ - GridView.builder( - //uniqueKey utilized so buttons that need to change color can dynamically rebuild - key: UniqueKey(), - itemCount: 100, - //squares kept in 10x10 gridview - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 10, - crossAxisSpacing: 0, - mainAxisSpacing: 0 - ), - shrinkWrap: true, - itemBuilder: (BuildContext context, int index) { - return maze1.button_grid[index]; - - } + Expanded( + child: GridView.builder( + //uniqueKey utilized so buttons that need to change color can dynamically rebuild + key: UniqueKey(), + itemCount: 100, + //squares kept in 10x10 gridview + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 10, + crossAxisSpacing: 0, + mainAxisSpacing: 0 + ), + shrinkWrap: true, + itemBuilder: (BuildContext context, int index) { + return maze1.button_grid[index]; + + } + ), ), Align( alignment: Alignment.bottomRight, diff --git a/lib/MazeTest.dart b/lib/MazeTest.dart index a16a15e..99ddb6e 100644 --- a/lib/MazeTest.dart +++ b/lib/MazeTest.dart @@ -9,6 +9,7 @@ import 'server.dart'; import 'instructions.dart'; import 'package:uuid/uuid.dart'; import 'userIDD.dart'; +import 'package:just_audio/just_audio.dart'; var uuid = Uuid(); @@ -28,7 +29,7 @@ List path2=[0,1,2,8,14,13,19,20,21,22,28,29,35]; bool timeOut2 = false; //when true, user is prohibited from entering new moves (so as not to overwhelm game) int attemptNum2 = 1; int consecErrors2 = 0; -int recentMove2; //records last move of user regardless of corectness +int recentMove2=0; //records last move of user regardless of corectness void main() { @@ -49,7 +50,7 @@ class MyApp extends StatelessWidget { primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), - home: MyHomePage(title: 'Flutter Demo Home Page'), + home: MyHomePage(title: 'Flutter Demo Home Page', key: null,), ); } } @@ -117,6 +118,15 @@ class gameButton extends StatefulWidget { class gameButtonState extends State { + //initialize audioplayer + AudioPlayer player2; + @override + void initState() { + super.initState(); + player2 = AudioPlayer(); + } +// stop initializing audioplayer + Color color; //initialize color state of buttons @@ -173,7 +183,8 @@ class gameButtonState extends State { if(widget.moveCheck()) { consecErrors2 = 0; maze2.button_grid[widget.id].color = Colors.green; - audioCache.play('ding2.mp3'); + player2.setAsset('assets/audio/ding2.mp3'); + player2.play(); errors2.add("correct"); maze2.button_grid[widget.id].displayImage = true; icon = Icons.check; @@ -201,6 +212,7 @@ class gameButtonState extends State { "trial": attemptNum.toString() }; String data = json.encode(dict2); createData("GMLT-6x6", uuid.v1().toString(), data, "1.0.0"); + player2.dispose(); showDialog( context: context, @@ -209,7 +221,7 @@ class gameButtonState extends State { return AlertDialog( title: new Text("Success!"), actions: [ - new FlatButton( + new TextButton( onPressed: () { resetGame(); Navigator.pop(context); @@ -217,7 +229,7 @@ class gameButtonState extends State { child: new Text("Practice Again") ), - new FlatButton( + new TextButton( onPressed: () { Navigator.push( context, @@ -240,7 +252,8 @@ class gameButtonState extends State { //keep track of how many consecutive errors user has made- if 3 then game should show next correct move consecErrors2++; maze2.button_grid[widget.id].color = Colors.red; - audioCache.play('buzz2.mp3'); + player2.setAsset('assets/audio/buzz2.mp3'); + player2.play(); errors2.add("incorrect"); maze2.button_grid[widget.id].displayImage=true; icon = Icons.clear; @@ -266,16 +279,17 @@ class gameButtonState extends State { Widget build(BuildContext context) { return Container( decoration: BoxDecoration(border: Border.all(color: Colors.black)), - child: FlatButton( - color: maze2.button_grid[widget.id].color, - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + child: TextButton( + style: TextButton.styleFrom( + backgroundColor: maze2.button_grid[widget.id].color, + ), onPressed: () { //what happens on buttonPress event- either nothing (if animation is taking place) or buttonPress function (defined above) called timeOut2?null:buttonPress(); }, child: maze2.button_grid[widget.id].displayImage?Column(// Replace with a Row for horizontal icon + text children: [ - maze2.button_grid[widget.id].displayImage?Icon(icon):null, + maze2.button_grid[widget.id].displayImage?Icon(icon, color:Colors.black):null, ], ):null )); @@ -365,21 +379,23 @@ class mazeState extends State { backgroundColor:Colors.cyan, body: Column( children: [ - GridView.builder( - //uniqueKey utilized so buttons that need to change color can dynamically rebuild - key: UniqueKey(), - itemCount: 36, - //squares kept in 10x10 gridview - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 6, - crossAxisSpacing: 0, - mainAxisSpacing: 0 - ), - shrinkWrap: true, - itemBuilder: (BuildContext context, int index) { - return maze2.button_grid[index]; - - } + Expanded( + child: GridView.builder( + //uniqueKey utilized so buttons that need to change color can dynamically rebuild + key: UniqueKey(), + itemCount: 36, + //squares kept in 10x10 gridview + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 6, + crossAxisSpacing: 0, + mainAxisSpacing: 0 + ), + shrinkWrap: true, + itemBuilder: (BuildContext context, int index) { + return maze2.button_grid[index]; + + } + ), ), Align( alignment: Alignment.bottomRight, diff --git a/lib/main.dart b/lib/main.dart index b42449e..36a7d25 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,8 +11,8 @@ import 'startingScreen.dart'; import 'Maze.dart'; import 'userIDD.dart'; import 'package:device_info_plus/device_info_plus.dart'; -import 'package:audioplayers/audio_cache.dart'; -import 'package:audioplayers/audioplayers.dart'; + +import 'package:just_audio/just_audio.dart'; //initialize new maze maze maze1= new maze(); @@ -33,8 +33,9 @@ bool timeOut = false; //when true, user is prohibited from entering new moves (s var dateTime = DateTime.now(); int attemptNum = 1; int consecErrors = 0; -int recentMove; //records last move of user regardless of corectness -final AudioCache audioCache = AudioCache(prefix: "audio/", fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP)); +int recentMove=0; //records last move of user regardless of corectness +//final AudioCache audioCache = AudioCache(prefix: "audio/", fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP)); + void main() { diff --git a/lib/startingScreen.dart b/lib/startingScreen.dart index a3669f9..fed4517 100644 --- a/lib/startingScreen.dart +++ b/lib/startingScreen.dart @@ -40,9 +40,11 @@ class startingScreenState extends State { child: SizedBox( width:55.0, height:55.0, - child: new FlatButton( - color: Colors.blue, - padding: EdgeInsets.all(0.0), + child: new TextButton( + style: TextButton.styleFrom( + backgroundColor: Colors.blue, + padding: EdgeInsets.all(0.0), + ), child: Image.asset("assets/mazeimage2.PNG", fit:BoxFit.fill), onPressed:() { Navigator.push( @@ -67,8 +69,11 @@ class startingScreenState extends State { child: SizedBox( width:55.0, height:55.0, - child: new RaisedButton( + child: new TextButton( + style: TextButton.styleFrom( padding: EdgeInsets.all(0.0), + ), + child: Image.asset("assets/mazeimage2.PNG", fit:BoxFit.fill), onPressed:() { Navigator.push( diff --git a/pubspec.lock b/pubspec.lock index 85be819..883afce 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" - audioplayers: - dependency: "direct main" + version: "2.6.1" + audio_session: + dependency: transitive description: - name: audioplayers + name: audio_session url: "https://pub.dartlang.org" source: hosted - version: "0.13.7" + version: "0.0.11" boolean_selector: dependency: transitive description: @@ -184,6 +184,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.1" + just_audio: + dependency: "direct main" + description: + name: just_audio + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.15+1" + just_audio_platform_interface: + dependency: transitive + description: + name: just_audio_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + just_audio_web: + dependency: transitive + description: + name: just_audio_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.3" matcher: dependency: transitive description: @@ -289,6 +310,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + rxdart: + dependency: transitive + description: + name: rxdart + url: "https://pub.dartlang.org" + source: hosted + version: "0.25.0" sky_engine: dependency: transitive description: flutter @@ -300,7 +328,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -335,7 +363,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 74a6397..e82b033 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.11.0 <3.0.0" dependencies: flutter: @@ -34,7 +34,7 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.3 device_info_plus: ^1.0.0-nullsafety.0 - audioplayers: ^0.13.2 + just_audio: dev_dependencies: