Skip to content
Snippets Groups Projects
Commit 65d81c34 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Improve some code / design

parent 4f252f37
No related branches found
No related tags found
1 merge request!23Resolve "Improve code/design"
Pipeline #5573 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.21 app.versionName=0.0.22
app.versionCode=21 app.versionCode=22
Improve some code/design.
Améliorations de code et de design.
...@@ -30,7 +30,6 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -30,7 +30,6 @@ class GameCubit extends HydratedCubit<GameState> {
position: state.currentGame.position, position: state.currentGame.position,
score: state.currentGame.score, score: state.currentGame.score,
); );
game.dump();
updateState(game); updateState(game);
} }
......
...@@ -35,8 +35,15 @@ class FetchDataHelper { ...@@ -35,8 +35,15 @@ class FetchDataHelper {
final Map<String, dynamic> rawMappingItems = rawMapping['items'] as Map<String, dynamic>; final Map<String, dynamic> rawMappingItems = rawMapping['items'] as Map<String, dynamic>;
rawMappingItems.forEach( rawMappingItems.forEach(
(String itemName, itemMappings) { (String itemName, itemMappings) {
List<String> rawIsCategories = itemMappings['is'] as List<String>; final List<String> rawIsCategories = [];
List<String> rawIsNotCategories = itemMappings['isnot'] as List<String>; 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( _mapping.add(GameItem(
item: Item( item: Item(
...@@ -65,8 +72,8 @@ class FetchDataHelper { ...@@ -65,8 +72,8 @@ class FetchDataHelper {
List<GameItem> items = _mapping; List<GameItem> items = _mapping;
// Remove items without enough data // Remove items without enough data
items.removeWhere((GameItem question) => items.removeWhere((GameItem gameItem) =>
(question.isCategory.isEmpty || question.isNotCategory.isEmpty)); (gameItem.isCategory.isEmpty || gameItem.isNotCategory.isEmpty));
items.shuffle(); items.shuffle();
......
...@@ -64,7 +64,7 @@ class Game { ...@@ -64,7 +64,7 @@ class Game {
isFinished = gameIsFinished; isFinished = gameIsFinished;
} }
GameItem getCurrentQuestion() { GameItem getCurrentGameItem() {
return items[position - 1]; return items[position - 1];
} }
......
...@@ -16,20 +16,22 @@ class ScreenGame extends StatelessWidget { ...@@ -16,20 +16,22 @@ class ScreenGame extends StatelessWidget {
builder: (BuildContext context, GameState gameState) { builder: (BuildContext context, GameState gameState) {
final Game currentGame = gameState.currentGame; final Game currentGame = gameState.currentGame;
return Container( return Column(
padding: const EdgeInsets.all(4),
child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
const SizedBox(height: 8), const SizedBox(height: 8),
const GameTopIndicatorWidget(), const GameTopIndicatorWidget(),
const SizedBox(height: 8), const SizedBox(height: 8),
!currentGame.isFinished Expanded(
child: !currentGame.isFinished
? const GameQuestionWidget() ? const GameQuestionWidget()
: const SizedBox(height: 8),
),
!currentGame.isFinished
? const SizedBox(height: 8)
: const GameBottomButtonsWidget(), : const GameBottomButtonsWidget(),
], ],
),
); );
}, },
); );
......
...@@ -16,12 +16,12 @@ class GameQuestionWidget extends StatelessWidget { ...@@ -16,12 +16,12 @@ class GameQuestionWidget extends StatelessWidget {
builder: (BuildContext context, GameState gameState) { builder: (BuildContext context, GameState gameState) {
final Game currentGame = gameState.currentGame; final Game currentGame = gameState.currentGame;
final GameItem currentQuestion = currentGame.getCurrentQuestion(); final GameItem currentGameItem = currentGame.getCurrentGameItem();
return Column( return Column(
children: [ children: [
OutlinedText( OutlinedText(
text: currentQuestion.item.text, text: currentGameItem.item.text,
fontSize: 50, fontSize: 50,
textColor: Theme.of(context).colorScheme.onSurface, textColor: Theme.of(context).colorScheme.onSurface,
), ),
...@@ -36,7 +36,7 @@ class GameQuestionWidget extends StatelessWidget { ...@@ -36,7 +36,7 @@ class GameQuestionWidget extends StatelessWidget {
borderRadius: const BorderRadius.all(Radius.circular(20)), borderRadius: const BorderRadius.all(Radius.circular(20)),
color: Theme.of(context).colorScheme.inversePrimary, color: Theme.of(context).colorScheme.inversePrimary,
), ),
child: GameButtonsYesNo(question: currentQuestion), child: GameButtonsYesNo(gameItem: currentGameItem),
), ),
], ],
); );
......
...@@ -7,12 +7,11 @@ import 'package:unicons/unicons.dart'; ...@@ -7,12 +7,11 @@ import 'package:unicons/unicons.dart';
import 'package:sortgame/cubit/game_cubit.dart'; import 'package:sortgame/cubit/game_cubit.dart';
import 'package:sortgame/models/data/category.dart'; import 'package:sortgame/models/data/category.dart';
import 'package:sortgame/models/data/game_item.dart'; import 'package:sortgame/models/data/game_item.dart';
import 'package:sortgame/ui/widgets/helpers/outlined_text_widget.dart';
class GameButtonsYesNo extends StatelessWidget { 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -21,12 +20,24 @@ class GameButtonsYesNo extends StatelessWidget { ...@@ -21,12 +20,24 @@ class GameButtonsYesNo extends StatelessWidget {
final bool pickInIsCategory = Random().nextBool(); final bool pickInIsCategory = Random().nextBool();
final List<Category> categories = final List<Category> categories =
pickInIsCategory ? question.isCategory : question.isNotCategory; pickInIsCategory ? gameItem.isCategory : gameItem.isNotCategory;
categories.shuffle(); categories.shuffle();
final Category category = categories.first; final Category category = categories.first;
final List<Widget> buttons = [ return Column(
children: [
Text(
category.text,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontSize: 40,
fontWeight: FontWeight.bold,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton( IconButton(
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,
iconSize: 80, iconSize: 80,
...@@ -49,18 +60,7 @@ class GameButtonsYesNo extends StatelessWidget { ...@@ -49,18 +60,7 @@ class GameButtonsYesNo extends StatelessWidget {
}, },
icon: const Icon(UniconsLine.thumbs_down), icon: const Icon(UniconsLine.thumbs_down),
), ),
]; ],
return Column(
children: [
OutlinedText(
text: category.text,
fontSize: 40,
textColor: Theme.of(context).colorScheme.onSurface,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: buttons,
) )
], ],
); );
......
...@@ -18,7 +18,7 @@ class OutlinedText extends StatelessWidget { ...@@ -18,7 +18,7 @@ class OutlinedText extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final double delta = fontSize / 35; final double delta = fontSize / 30;
return Text( return Text(
text, text,
......
...@@ -3,7 +3,7 @@ description: A sorting game application. ...@@ -3,7 +3,7 @@ description: A sorting game application.
publish_to: 'none' publish_to: 'none'
version: 0.0.21+21 version: 0.0.22+22
environment: environment:
sdk: '^3.0.0' sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment