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

Merge branch '26-improve-code-design' into 'master'

Resolve "Improve code/design"

Closes #26

See merge request !23
parents 4f252f37 65d81c34
Branches
Tags Release_0.0.22_22
1 merge request!23Resolve "Improve code/design"
Pipeline #5577 passed
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
Improve some code/design.
Améliorations de code et de design.
......@@ -30,7 +30,6 @@ class GameCubit extends HydratedCubit<GameState> {
position: state.currentGame.position,
score: state.currentGame.score,
);
game.dump();
updateState(game);
}
......
......@@ -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();
......
......@@ -64,7 +64,7 @@ class Game {
isFinished = gameIsFinished;
}
GameItem getCurrentQuestion() {
GameItem getCurrentGameItem() {
return items[position - 1];
}
......
......@@ -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(
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 8),
const GameTopIndicatorWidget(),
const SizedBox(height: 8),
!currentGame.isFinished
Expanded(
child: !currentGame.isFinished
? const GameQuestionWidget()
: const SizedBox(height: 8),
),
!currentGame.isFinished
? const SizedBox(height: 8)
: const GameBottomButtonsWidget(),
],
),
);
},
);
......
......@@ -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),
),
],
);
......
......@@ -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,12 +20,24 @@ 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 = [
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(
color: Theme.of(context).colorScheme.onSurface,
iconSize: 80,
......@@ -49,18 +60,7 @@ class GameButtonsYesNo extends StatelessWidget {
},
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 {
@override
Widget build(BuildContext context) {
final double delta = fontSize / 35;
final double delta = fontSize / 30;
return Text(
text,
......
......@@ -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'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment