From 65d81c34b9d163a3f86f67626041580dbcf09116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Wed, 17 Apr 2024 17:04:51 +0200 Subject: [PATCH] Improve some code / design --- android/gradle.properties | 4 +- .../metadata/android/en-US/changelogs/22.txt | 1 + .../metadata/android/fr-FR/changelogs/22.txt | 1 + lib/cubit/game_cubit.dart | 1 - lib/data/fetch_data_helper.dart | 15 ++-- lib/models/game.dart | 2 +- lib/ui/screens/screen_game.dart | 28 ++++---- lib/ui/widgets/game_question.dart | 6 +- lib/ui/widgets/games/buttons_yes_no.dart | 68 +++++++++---------- .../widgets/helpers/outlined_text_widget.dart | 2 +- pubspec.yaml | 2 +- 11 files changed, 70 insertions(+), 60 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/22.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/22.txt diff --git a/android/gradle.properties b/android/gradle.properties index eeed3ef..ed86f0f 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.21 -app.versionCode=21 +app.versionName=0.0.22 +app.versionCode=22 diff --git a/fastlane/metadata/android/en-US/changelogs/22.txt b/fastlane/metadata/android/en-US/changelogs/22.txt new file mode 100644 index 0000000..f5f06e8 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/22.txt @@ -0,0 +1 @@ +Improve some code/design. diff --git a/fastlane/metadata/android/fr-FR/changelogs/22.txt b/fastlane/metadata/android/fr-FR/changelogs/22.txt new file mode 100644 index 0000000..3be1a61 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/22.txt @@ -0,0 +1 @@ +Améliorations de code et de design. diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart index 8a2551c..3841e16 100644 --- a/lib/cubit/game_cubit.dart +++ b/lib/cubit/game_cubit.dart @@ -30,7 +30,6 @@ class GameCubit extends HydratedCubit<GameState> { position: state.currentGame.position, score: state.currentGame.score, ); - game.dump(); updateState(game); } diff --git a/lib/data/fetch_data_helper.dart b/lib/data/fetch_data_helper.dart index 2b5148c..fd7ac7a 100644 --- a/lib/data/fetch_data_helper.dart +++ b/lib/data/fetch_data_helper.dart @@ -35,8 +35,15 @@ class FetchDataHelper { final Map<String, dynamic> rawMappingItems = rawMapping['items'] as Map<String, dynamic>; rawMappingItems.forEach( (String itemName, itemMappings) { - List<String> rawIsCategories = itemMappings['is'] as List<String>; - List<String> rawIsNotCategories = itemMappings['isnot'] as List<String>; + final List<String> rawIsCategories = []; + for (var category in itemMappings['is'] as List<dynamic>) { + rawIsCategories.add(category.toString()); + } + + final List<String> rawIsNotCategories = []; + for (var category in itemMappings['isnot'] as List<dynamic>) { + rawIsNotCategories.add(category.toString()); + } _mapping.add(GameItem( item: Item( @@ -65,8 +72,8 @@ class FetchDataHelper { List<GameItem> items = _mapping; // Remove items without enough data - items.removeWhere((GameItem question) => - (question.isCategory.isEmpty || question.isNotCategory.isEmpty)); + items.removeWhere((GameItem gameItem) => + (gameItem.isCategory.isEmpty || gameItem.isNotCategory.isEmpty)); items.shuffle(); diff --git a/lib/models/game.dart b/lib/models/game.dart index 797ac0b..fcc9097 100644 --- a/lib/models/game.dart +++ b/lib/models/game.dart @@ -64,7 +64,7 @@ class Game { isFinished = gameIsFinished; } - GameItem getCurrentQuestion() { + GameItem getCurrentGameItem() { return items[position - 1]; } diff --git a/lib/ui/screens/screen_game.dart b/lib/ui/screens/screen_game.dart index 154842b..f285927 100644 --- a/lib/ui/screens/screen_game.dart +++ b/lib/ui/screens/screen_game.dart @@ -16,20 +16,22 @@ class ScreenGame extends StatelessWidget { builder: (BuildContext context, GameState gameState) { final Game currentGame = gameState.currentGame; - return Container( - padding: const EdgeInsets.all(4), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const SizedBox(height: 8), - const GameTopIndicatorWidget(), - const SizedBox(height: 8), - !currentGame.isFinished + return Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox(height: 8), + const GameTopIndicatorWidget(), + const SizedBox(height: 8), + Expanded( + child: !currentGame.isFinished ? const GameQuestionWidget() - : const GameBottomButtonsWidget(), - ], - ), + : const SizedBox(height: 8), + ), + !currentGame.isFinished + ? const SizedBox(height: 8) + : const GameBottomButtonsWidget(), + ], ); }, ); diff --git a/lib/ui/widgets/game_question.dart b/lib/ui/widgets/game_question.dart index 83153dc..1f0c6da 100644 --- a/lib/ui/widgets/game_question.dart +++ b/lib/ui/widgets/game_question.dart @@ -16,12 +16,12 @@ class GameQuestionWidget extends StatelessWidget { builder: (BuildContext context, GameState gameState) { final Game currentGame = gameState.currentGame; - final GameItem currentQuestion = currentGame.getCurrentQuestion(); + final GameItem currentGameItem = currentGame.getCurrentGameItem(); return Column( children: [ OutlinedText( - text: currentQuestion.item.text, + text: currentGameItem.item.text, fontSize: 50, textColor: Theme.of(context).colorScheme.onSurface, ), @@ -36,7 +36,7 @@ class GameQuestionWidget extends StatelessWidget { borderRadius: const BorderRadius.all(Radius.circular(20)), color: Theme.of(context).colorScheme.inversePrimary, ), - child: GameButtonsYesNo(question: currentQuestion), + child: GameButtonsYesNo(gameItem: currentGameItem), ), ], ); diff --git a/lib/ui/widgets/games/buttons_yes_no.dart b/lib/ui/widgets/games/buttons_yes_no.dart index 44f9280..3efd687 100644 --- a/lib/ui/widgets/games/buttons_yes_no.dart +++ b/lib/ui/widgets/games/buttons_yes_no.dart @@ -7,12 +7,11 @@ import 'package:unicons/unicons.dart'; import 'package:sortgame/cubit/game_cubit.dart'; import 'package:sortgame/models/data/category.dart'; import 'package:sortgame/models/data/game_item.dart'; -import 'package:sortgame/ui/widgets/helpers/outlined_text_widget.dart'; class GameButtonsYesNo extends StatelessWidget { - const GameButtonsYesNo({super.key, required this.question}); + const GameButtonsYesNo({super.key, required this.gameItem}); - final GameItem question; + final GameItem gameItem; @override Widget build(BuildContext context) { @@ -21,46 +20,47 @@ class GameButtonsYesNo extends StatelessWidget { final bool pickInIsCategory = Random().nextBool(); final List<Category> categories = - pickInIsCategory ? question.isCategory : question.isNotCategory; + pickInIsCategory ? gameItem.isCategory : gameItem.isNotCategory; categories.shuffle(); final Category category = categories.first; - final List<Widget> buttons = [ - IconButton( - color: Theme.of(context).colorScheme.onSurface, - iconSize: 80, - onPressed: () { - if (pickInIsCategory) { - gameCubit.increaseScore(1); - } - gameCubit.increasePosition(); - }, - icon: const Icon(UniconsLine.thumbs_up), - ), - IconButton( - color: Theme.of(context).colorScheme.onSurface, - iconSize: 80, - onPressed: () { - if (!pickInIsCategory) { - gameCubit.increaseScore(1); - } - gameCubit.increasePosition(); - }, - icon: const Icon(UniconsLine.thumbs_down), - ), - ]; - return Column( children: [ - OutlinedText( - text: category.text, - fontSize: 40, - textColor: Theme.of(context).colorScheme.onSurface, + Text( + category.text, + style: TextStyle( + color: Theme.of(context).colorScheme.onSurface, + fontSize: 40, + fontWeight: FontWeight.bold, + ), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: buttons, + children: [ + IconButton( + color: Theme.of(context).colorScheme.onSurface, + iconSize: 80, + onPressed: () { + if (pickInIsCategory) { + gameCubit.increaseScore(1); + } + gameCubit.increasePosition(); + }, + icon: const Icon(UniconsLine.thumbs_up), + ), + IconButton( + color: Theme.of(context).colorScheme.onSurface, + iconSize: 80, + onPressed: () { + if (!pickInIsCategory) { + gameCubit.increaseScore(1); + } + gameCubit.increasePosition(); + }, + icon: const Icon(UniconsLine.thumbs_down), + ), + ], ) ], ); diff --git a/lib/ui/widgets/helpers/outlined_text_widget.dart b/lib/ui/widgets/helpers/outlined_text_widget.dart index bdf29f2..79644ac 100644 --- a/lib/ui/widgets/helpers/outlined_text_widget.dart +++ b/lib/ui/widgets/helpers/outlined_text_widget.dart @@ -18,7 +18,7 @@ class OutlinedText extends StatelessWidget { @override Widget build(BuildContext context) { - final double delta = fontSize / 35; + final double delta = fontSize / 30; return Text( text, diff --git a/pubspec.yaml b/pubspec.yaml index b43ae33..220bed6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A sorting game application. publish_to: 'none' -version: 0.0.21+21 +version: 0.0.22+22 environment: sdk: '^3.0.0' -- GitLab