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

Clean / improve / update code

parent ab06b5d2
Branches
Tags
1 merge request!11Resolve "Clean / improve / update code"
Pipeline #6060 passed
This commit is part of merge request !11. Comments created here will be created in the context of that merge request.
Showing
with 375 additions and 197 deletions
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.10 app.versionName=0.0.11
app.versionCode=10 app.versionCode=11
assets/ui/button_back.png

3.68 KiB | W: | H:

assets/ui/button_back.png

2.37 KiB | W: | H:

assets/ui/button_back.png
assets/ui/button_back.png
assets/ui/button_back.png
assets/ui/button_back.png
  • 2-up
  • Swipe
  • Onion skin
assets/ui/button_delete_saved_game.png

5.68 KiB | W: | H:

assets/ui/button_delete_saved_game.png

7.65 KiB | W: | H:

assets/ui/button_delete_saved_game.png
assets/ui/button_delete_saved_game.png
assets/ui/button_delete_saved_game.png
assets/ui/button_delete_saved_game.png
  • 2-up
  • Swipe
  • Onion skin
assets/ui/button_resume_game.png

3.57 KiB | W: | H:

assets/ui/button_resume_game.png

3.35 KiB | W: | H:

assets/ui/button_resume_game.png
assets/ui/button_resume_game.png
assets/ui/button_resume_game.png
assets/ui/button_resume_game.png
  • 2-up
  • Swipe
  • Onion skin
assets/ui/button_start.png

3.91 KiB | W: | H:

assets/ui/button_start.png

2.99 KiB | W: | H:

assets/ui/button_start.png
assets/ui/button_start.png
assets/ui/button_start.png
assets/ui/button_start.png
  • 2-up
  • Swipe
  • Onion skin
Clean / improve / update code and UI.
Nettoyage / amélioration / mise à jour de code et de l'interface.
...@@ -31,9 +31,4 @@ class DefaultGameSettings { ...@@ -31,9 +31,4 @@ class DefaultGameSettings {
printlog('Did not find any available value for game parameter "$parameterCode".'); printlog('Did not find any available value for game parameter "$parameterCode".');
return []; return [];
} }
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
} }
...@@ -25,9 +25,4 @@ class DefaultGlobalSettings { ...@@ -25,9 +25,4 @@ class DefaultGlobalSettings {
printlog('Did not find any available value for global parameter "$parameterCode".'); printlog('Did not find any available value for global parameter "$parameterCode".');
return []; return [];
} }
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
} }
...@@ -89,12 +89,14 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -89,12 +89,14 @@ class GameCubit extends HydratedCubit<GameState> {
void robotPlay() async { void robotPlay() async {
if (!state.currentGame.isFinished && !state.currentGame.isCurrentPlayerHuman()) { if (!state.currentGame.isFinished && !state.currentGame.isCurrentPlayerHuman()) {
final int pickedCell = RobotPlayer.pickCell(state.currentGame); final int? pickedCell = RobotPlayer.pickCell(state.currentGame);
await Future.delayed(const Duration(milliseconds: 500)); await Future.delayed(const Duration(milliseconds: 500));
if (pickedCell != null) {
tapOnCell(pickedCell); tapOnCell(pickedCell);
} }
} }
}
void tapOnCell(int cellIndex) async { void tapOnCell(int cellIndex) async {
printlog('tapOnCell: $cellIndex'); printlog('tapOnCell: $cellIndex');
......
...@@ -84,10 +84,6 @@ class MyApp extends StatelessWidget { ...@@ -84,10 +84,6 @@ class MyApp extends StatelessWidget {
final List<String> assets = []; final List<String> assets = [];
const List<String> gameImages = [ const List<String> gameImages = [
'button_back',
'button_delete_saved_game',
'button_resume_game',
'button_start',
'game_fail', 'game_fail',
'game_win', 'game_win',
'placeholder', 'placeholder',
......
import 'package:awale/models/game/game.dart'; import 'package:awale/models/game/game.dart';
class RobotPlayer { class RobotPlayer {
static pickCell(Game currentGame) { static int? pickCell(Game currentGame) {
List<int> allowedMoves = []; List<int> allowedMoves = [];
for (int cellIndex = 0; cellIndex < currentGame.board.cells.length; cellIndex++) { for (int cellIndex = 0; cellIndex < currentGame.board.cells.length; cellIndex++) {
...@@ -11,6 +11,10 @@ class RobotPlayer { ...@@ -11,6 +11,10 @@ class RobotPlayer {
} }
} }
if (allowedMoves.isEmpty) {
return null;
}
allowedMoves.shuffle(); allowedMoves.shuffle();
final int pickedCellIndex = allowedMoves[0]; final int pickedCellIndex = allowedMoves[0];
......
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:awale/utils/color_extensions.dart';
class StyledButton extends StatelessWidget {
const StyledButton({
super.key,
required this.color,
required this.onPressed,
this.onLongPress,
required this.child,
});
final Color color;
final VoidCallback? onPressed;
final VoidCallback? onLongPress;
final Widget child;
factory StyledButton.text({
Key? key,
required VoidCallback? onPressed,
VoidCallback? onLongPress,
required String caption,
required Color color,
}) {
final Widget captionWidget = AutoSizeText(
caption,
maxLines: 1,
style: TextStyle(
inherit: true,
fontWeight: FontWeight.w900,
color: color.darken(60),
shadows: [
Shadow(
blurRadius: 5.0,
color: color.lighten(60),
offset: const Offset(2, 2),
),
Shadow(
blurRadius: 5.0,
color: color.lighten(60),
offset: const Offset(2, -2),
),
Shadow(
blurRadius: 5.0,
color: color.lighten(60),
offset: const Offset(-2, 2),
),
Shadow(
blurRadius: 5.0,
color: color.lighten(60),
offset: const Offset(-2, -2),
),
],
),
);
return StyledButton(
color: color,
onPressed: onPressed,
onLongPress: onLongPress,
child: captionWidget,
);
}
factory StyledButton.icon({
Key? key,
required VoidCallback? onPressed,
VoidCallback? onLongPress,
required Icon icon,
required Color color,
required double iconSize,
}) {
return StyledButton(
color: color,
onPressed: onPressed,
onLongPress: onLongPress,
child: Icon(
icon.icon,
color: icon.color ?? color.darken(60),
size: iconSize,
shadows: [
Shadow(
blurRadius: 5.0,
color: color.lighten(60),
offset: const Offset(2, 2),
),
Shadow(
blurRadius: 5.0,
color: color.lighten(60),
offset: const Offset(2, -2),
),
Shadow(
blurRadius: 5.0,
color: color.lighten(60),
offset: const Offset(-2, 2),
),
Shadow(
blurRadius: 5.0,
color: color.lighten(60),
offset: const Offset(-2, -2),
),
],
),
);
}
@override
Widget build(BuildContext context) {
const double borderWidth = 4;
final Color borderColor = color.darken(40);
const double borderRadius = 10;
return Container(
margin: const EdgeInsets.all(2),
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
color: color,
border: Border.all(
color: borderColor,
width: borderWidth,
),
borderRadius: BorderRadius.circular(borderRadius),
),
child: CustomPaint(
painter: StyledButtonPainter(
baseColor: color,
),
child: MaterialButton(
onPressed: onPressed,
onLongPress: onLongPress,
padding: const EdgeInsets.all(8),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
minWidth: 40,
child: child,
),
),
);
}
}
class StyledButtonPainter extends CustomPainter {
StyledButtonPainter({
required this.baseColor,
});
final Color baseColor;
@override
void paint(Canvas canvas, Size size) {
final Color lightColor = baseColor.lighten(20);
final Color darkColor = baseColor.darken(20);
final Paint paint = Paint()..style = PaintingStyle.fill;
const double cornerRadius = 6;
Path topPath = Path()
..moveTo(cornerRadius, 0)
..lineTo(size.width - cornerRadius, 0)
..arcToPoint(
Offset(size.width, cornerRadius),
radius: const Radius.circular(cornerRadius),
)
..lineTo(size.width, size.height * .35)
..quadraticBezierTo(
size.width * .4,
size.height * .1,
0,
size.height * .3,
)
..lineTo(0, cornerRadius)
..arcToPoint(
const Offset(cornerRadius, 0),
radius: const Radius.circular(cornerRadius),
);
Path bottomPath = Path()
..moveTo(cornerRadius, size.height)
..lineTo(size.width - cornerRadius, size.height)
..arcToPoint(
Offset(size.width, size.height - cornerRadius),
radius: const Radius.circular(cornerRadius),
clockwise: false,
)
..lineTo(size.width, size.height * .7)
..quadraticBezierTo(
size.width * .6,
size.height * .9,
0,
size.height * .7,
)
..lineTo(0, size.height - cornerRadius)
..arcToPoint(
Offset(cornerRadius, size.height),
radius: const Radius.circular(cornerRadius),
clockwise: false,
);
paint.color = lightColor;
canvas.drawPath(topPath, paint);
paint.color = darkColor;
canvas.drawPath(bottomPath, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
...@@ -5,11 +5,10 @@ import 'package:awale/config/default_game_settings.dart'; ...@@ -5,11 +5,10 @@ import 'package:awale/config/default_game_settings.dart';
import 'package:awale/config/default_global_settings.dart'; import 'package:awale/config/default_global_settings.dart';
import 'package:awale/cubit/settings_game_cubit.dart'; import 'package:awale/cubit/settings_game_cubit.dart';
import 'package:awale/cubit/settings_global_cubit.dart'; import 'package:awale/cubit/settings_global_cubit.dart';
import 'package:awale/ui/parameters/parameter_painter.dart';
import 'package:awale/ui/widgets/actions/button_delete_saved_game.dart'; import 'package:awale/ui/widgets/actions/button_delete_saved_game.dart';
import 'package:awale/ui/widgets/actions/button_game_start_new.dart'; import 'package:awale/ui/widgets/actions/button_game_start_new.dart';
import 'package:awale/ui/widgets/actions/button_resume_saved_game.dart'; import 'package:awale/ui/widgets/actions/button_resume_saved_game.dart';
import 'package:awale/ui/parameters/parameter_image.dart'; import 'package:awale/ui/parameters/parameter_widget.dart';
class ParametersLayout extends StatelessWidget { class ParametersLayout extends StatelessWidget {
const ParametersLayout({super.key, required this.canResume}); const ParametersLayout({super.key, required this.canResume});
...@@ -35,21 +34,27 @@ class ParametersLayout extends StatelessWidget { ...@@ -35,21 +34,27 @@ class ParametersLayout extends StatelessWidget {
lines.add(SizedBox(height: separatorHeight)); lines.add(SizedBox(height: separatorHeight));
} }
lines.add(SizedBox(height: separatorHeight)); lines.add(Expanded(
child: SizedBox(height: separatorHeight),
));
if (canResume == false) { if (canResume == false) {
// Start new game // Start new game
lines.add(const Expanded( lines.add(
const AspectRatio(
aspectRatio: 3,
child: StartNewGameButton(), child: StartNewGameButton(),
)); ),
);
} else { } else {
// Resume game // Resume game
lines.add(const Expanded( lines.add(const AspectRatio(
aspectRatio: 3,
child: ResumeSavedGameButton(), child: ResumeSavedGameButton(),
)); ));
// Delete saved game // Delete saved game
lines.add(SizedBox.square( lines.add(SizedBox.square(
dimension: MediaQuery.of(context).size.width / 4, dimension: MediaQuery.of(context).size.width / 5,
child: const DeleteSavedGameButton(), child: const DeleteSavedGameButton(),
)); ));
} }
...@@ -102,44 +107,26 @@ class ParametersLayout extends StatelessWidget { ...@@ -102,44 +107,26 @@ class ParametersLayout extends StatelessWidget {
? globalSettingsCubit.getParameterValue(code) ? globalSettingsCubit.getParameterValue(code)
: gameSettingsCubit.getParameterValue(code); : gameSettingsCubit.getParameterValue(code);
final bool isActive = (value == currentValue); final bool isSelected = (value == currentValue);
final double displayWidth = MediaQuery.of(context).size.width; final double displayWidth = MediaQuery.of(context).size.width;
final double itemWidth = displayWidth / availableValues.length - 26; final double itemWidth = displayWidth / availableValues.length - 4;
final bool displayedWithAssets =
DefaultGlobalSettings.displayedWithAssets.contains(code) ||
DefaultGameSettings.displayedWithAssets.contains(code);
return TextButton( return SizedBox.square(
child: Container(
child: displayedWithAssets
? SizedBox.square(
dimension: itemWidth, dimension: itemWidth,
child: ParameterImage( child: ParameterWidget(
code: code, code: code,
value: value, value: value,
isSelected: isActive, isSelected: isSelected,
), size: itemWidth,
)
: CustomPaint(
size: Size(itemWidth, itemWidth),
willChange: false,
painter: ParameterPainter(
code: code,
value: value,
isSelected: isActive,
gameSettings: gameSettingsState.settings, gameSettings: gameSettingsState.settings,
globalSettings: globalSettingsState.settings, globalSettings: globalSettingsState.settings,
),
isComplex: true,
),
),
onPressed: () { onPressed: () {
isGlobal isGlobal
? globalSettingsCubit.setParameterValue(code, value) ? globalSettingsCubit.setParameterValue(code, value)
: gameSettingsCubit.setParameterValue(code, value); : gameSettingsCubit.setParameterValue(code, value);
}, },
),
); );
}, },
); );
......
import 'package:flutter/material.dart';
class ParameterImage extends StatelessWidget {
const ParameterImage({
super.key,
required this.code,
required this.value,
required this.isSelected,
});
final String code;
final String value;
final bool isSelected;
static const Color buttonBackgroundColor = Colors.white;
static const Color buttonBorderColorActive = Colors.blue;
static const Color buttonBorderColorInactive = Colors.white;
static const double buttonBorderWidth = 8.0;
static const double buttonBorderRadius = 8.0;
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: buttonBackgroundColor,
borderRadius: BorderRadius.circular(buttonBorderRadius),
border: Border.all(
color: isSelected ? buttonBorderColorActive : buttonBorderColorInactive,
width: buttonBorderWidth,
),
),
child: Image(
image: AssetImage('assets/ui/${code}_$value.png'),
fit: BoxFit.fill,
),
);
}
}
...@@ -2,7 +2,6 @@ import 'dart:math'; ...@@ -2,7 +2,6 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:awale/config/default_game_settings.dart';
import 'package:awale/models/settings/settings_game.dart'; import 'package:awale/models/settings/settings_game.dart';
import 'package:awale/models/settings/settings_global.dart'; import 'package:awale/models/settings/settings_global.dart';
import 'package:awale/utils/tools.dart'; import 'package:awale/utils/tools.dart';
...@@ -11,14 +10,12 @@ class ParameterPainter extends CustomPainter { ...@@ -11,14 +10,12 @@ class ParameterPainter extends CustomPainter {
const ParameterPainter({ const ParameterPainter({
required this.code, required this.code,
required this.value, required this.value,
required this.isSelected,
required this.gameSettings, required this.gameSettings,
required this.globalSettings, required this.globalSettings,
}); });
final String code; final String code;
final String value; final String value;
final bool isSelected;
final GameSettings gameSettings; final GameSettings gameSettings;
final GlobalSettings globalSettings; final GlobalSettings globalSettings;
...@@ -27,26 +24,11 @@ class ParameterPainter extends CustomPainter { ...@@ -27,26 +24,11 @@ class ParameterPainter extends CustomPainter {
// force square // force square
final double canvasSize = min(size.width, size.height); final double canvasSize = min(size.width, size.height);
const Color borderColorEnabled = Colors.blue;
const Color borderColorDisabled = Colors.white;
// "enabled/disabled" border
final paint = Paint();
paint.style = PaintingStyle.stroke;
paint.color = isSelected ? borderColorEnabled : borderColorDisabled;
paint.strokeJoin = StrokeJoin.round;
paint.strokeWidth = 10;
canvas.drawRect(
Rect.fromPoints(const Offset(0, 0), Offset(canvasSize, canvasSize)), paint);
// content // content
switch (code) { switch (code) {
case DefaultGameSettings.parameterCodeGameMode:
paintGameModeParameterItem(value, canvas, canvasSize);
break;
default: default:
printlog('Unknown parameter: $code/$value'); printlog('Unknown parameter: $code/$value');
paintUnknownParameterItem(value, canvas, canvasSize); paintUnknownParameterItem(canvas, canvasSize);
} }
} }
...@@ -57,7 +39,6 @@ class ParameterPainter extends CustomPainter { ...@@ -57,7 +39,6 @@ class ParameterPainter extends CustomPainter {
// "unknown" parameter -> simple block with text // "unknown" parameter -> simple block with text
void paintUnknownParameterItem( void paintUnknownParameterItem(
final String value,
final Canvas canvas, final Canvas canvas,
final double size, final double size,
) { ) {
...@@ -65,12 +46,8 @@ class ParameterPainter extends CustomPainter { ...@@ -65,12 +46,8 @@ class ParameterPainter extends CustomPainter {
paint.strokeJoin = StrokeJoin.round; paint.strokeJoin = StrokeJoin.round;
paint.strokeWidth = 3; paint.strokeWidth = 3;
paint.color = Colors.grey;
paint.style = PaintingStyle.fill;
canvas.drawRect(Rect.fromPoints(const Offset(0, 0), Offset(size, size)), paint);
final textSpan = TextSpan( final textSpan = TextSpan(
text: '?\n$value', text: '$code\n$value',
style: const TextStyle( style: const TextStyle(
color: Colors.black, color: Colors.black,
fontSize: 18, fontSize: 18,
...@@ -91,63 +68,4 @@ class ParameterPainter extends CustomPainter { ...@@ -91,63 +68,4 @@ class ParameterPainter extends CustomPainter {
), ),
); );
} }
void paintGameModeParameterItem(
final String value,
final Canvas canvas,
final double size,
) {
String text = '';
Color baseColor = Colors.grey;
switch (value) {
case DefaultGameSettings.gameModeHumanVsHuman:
text = '🧑 🧑';
baseColor = Colors.green;
break;
case DefaultGameSettings.gameModeHumanVsRobot:
text = '🧑 🤖';
baseColor = Colors.pink;
break;
case DefaultGameSettings.gameModeRobotVsHuman:
text = '🤖 🧑';
baseColor = Colors.pink;
break;
case DefaultGameSettings.gameModeRobotVsRobot:
text = '🤖 🤖';
baseColor = Colors.brown;
break;
default:
}
final paint = Paint();
paint.strokeJoin = StrokeJoin.round;
paint.strokeWidth = 3;
paint.color = baseColor;
paint.style = PaintingStyle.fill;
canvas.drawRect(Rect.fromPoints(const Offset(0, 0), Offset(size, size)), paint);
final textSpan = TextSpan(
text: text,
style: const TextStyle(
color: Colors.black,
fontSize: 22,
fontWeight: FontWeight.bold,
),
);
final textPainter = TextPainter(
text: textSpan,
textDirection: TextDirection.ltr,
textAlign: TextAlign.center,
);
textPainter.layout();
textPainter.paint(
canvas,
Offset(
(size - textPainter.width) * 0.5,
(size - textPainter.height) * 0.5,
),
);
}
} }
import 'package:flutter/material.dart';
import 'package:awale/config/default_game_settings.dart';
import 'package:awale/models/settings/settings_game.dart';
import 'package:awale/models/settings/settings_global.dart';
import 'package:awale/ui/helpers/styled_button.dart';
import 'package:awale/utils/tools.dart';
class ParameterWidget extends StatelessWidget {
const ParameterWidget({
super.key,
required this.code,
required this.value,
required this.isSelected,
required this.size,
required this.gameSettings,
required this.globalSettings,
required this.onPressed,
});
final String code;
final String value;
final bool isSelected;
final double size;
final GameSettings gameSettings;
final GlobalSettings globalSettings;
final VoidCallback onPressed;
static const Color buttonColorActive = Colors.blue;
static const Color buttonColorInactive = Colors.white;
static const double buttonBorderWidth = 4.0;
static const double buttonBorderRadius = 12.0;
@override
Widget build(BuildContext context) {
Widget content = const SizedBox.shrink();
switch (code) {
case DefaultGameSettings.parameterCodeGameMode:
content = getGameModeParameterItem();
break;
default:
printlog('Unknown parameter: $code/$value');
content = getUnknownParameterItem();
}
final Color buttonColor = isSelected ? buttonColorActive : buttonColorInactive;
return Container(
decoration: BoxDecoration(
color: buttonColor,
borderRadius: BorderRadius.circular(buttonBorderRadius),
border: Border.all(
color: buttonColor,
width: buttonBorderWidth,
),
),
child: content,
);
}
// "unknown" parameter -> simple block with text
Widget getUnknownParameterItem() {
return StyledButton.text(
caption: '$code / $value',
color: Colors.grey,
onPressed: null,
);
}
Widget getGameModeParameterItem() {
String text = '';
Color baseColor = Colors.grey;
switch (value) {
case DefaultGameSettings.gameModeHumanVsHuman:
text = '🧑 🧑';
baseColor = Colors.green;
break;
case DefaultGameSettings.gameModeHumanVsRobot:
text = '🧑 🤖';
baseColor = Colors.pink;
break;
case DefaultGameSettings.gameModeRobotVsHuman:
text = '🤖 🧑';
baseColor = Colors.pink;
break;
case DefaultGameSettings.gameModeRobotVsRobot:
text = '🤖 🤖';
baseColor = Colors.brown;
break;
default:
}
return StyledButton.text(
caption: text,
color: baseColor,
onPressed: onPressed,
);
}
}
...@@ -2,20 +2,22 @@ import 'package:flutter/material.dart'; ...@@ -2,20 +2,22 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:awale/cubit/game_cubit.dart'; import 'package:awale/cubit/game_cubit.dart';
import 'package:awale/ui/helpers/styled_button.dart';
class DeleteSavedGameButton extends StatelessWidget { class DeleteSavedGameButton extends StatelessWidget {
const DeleteSavedGameButton({super.key}); const DeleteSavedGameButton({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return TextButton( return StyledButton(
color: Colors.grey,
onPressed: () {
BlocProvider.of<GameCubit>(context).deleteSavedGame();
},
child: const Image( child: const Image(
image: AssetImage('assets/ui/button_delete_saved_game.png'), image: AssetImage('assets/ui/button_delete_saved_game.png'),
fit: BoxFit.fill, fit: BoxFit.fill,
), ),
onPressed: () {
BlocProvider.of<GameCubit>(context).deleteSavedGame();
},
); );
} }
} }
...@@ -2,20 +2,22 @@ import 'package:flutter/material.dart'; ...@@ -2,20 +2,22 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:awale/cubit/game_cubit.dart'; import 'package:awale/cubit/game_cubit.dart';
import 'package:awale/ui/helpers/styled_button.dart';
class QuitGameButton extends StatelessWidget { class QuitGameButton extends StatelessWidget {
const QuitGameButton({super.key}); const QuitGameButton({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ElevatedButton( return StyledButton(
color: Colors.red,
onPressed: () {
BlocProvider.of<GameCubit>(context).quitGame();
},
child: const Image( child: const Image(
image: AssetImage('assets/ui/button_back.png'), image: AssetImage('assets/ui/button_back.png'),
fit: BoxFit.fill, fit: BoxFit.fill,
), ),
onPressed: () {
BlocProvider.of<GameCubit>(context).quitGame();
},
); );
} }
} }
...@@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; ...@@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:awale/cubit/game_cubit.dart'; import 'package:awale/cubit/game_cubit.dart';
import 'package:awale/cubit/settings_game_cubit.dart'; import 'package:awale/cubit/settings_game_cubit.dart';
import 'package:awale/cubit/settings_global_cubit.dart'; import 'package:awale/cubit/settings_global_cubit.dart';
import 'package:awale/ui/helpers/styled_button.dart';
class StartNewGameButton extends StatelessWidget { class StartNewGameButton extends StatelessWidget {
const StartNewGameButton({super.key}); const StartNewGameButton({super.key});
...@@ -14,17 +15,18 @@ class StartNewGameButton extends StatelessWidget { ...@@ -14,17 +15,18 @@ class StartNewGameButton extends StatelessWidget {
builder: (BuildContext context, GameSettingsState gameSettingsState) { builder: (BuildContext context, GameSettingsState gameSettingsState) {
return BlocBuilder<GlobalSettingsCubit, GlobalSettingsState>( return BlocBuilder<GlobalSettingsCubit, GlobalSettingsState>(
builder: (BuildContext context, GlobalSettingsState globalSettingsState) { builder: (BuildContext context, GlobalSettingsState globalSettingsState) {
return TextButton( return StyledButton(
child: const Image( color: Colors.blue,
image: AssetImage('assets/ui/button_start.png'),
fit: BoxFit.fill,
),
onPressed: () { onPressed: () {
BlocProvider.of<GameCubit>(context).startNewGame( BlocProvider.of<GameCubit>(context).startNewGame(
gameSettings: gameSettingsState.settings, gameSettings: gameSettingsState.settings,
globalSettings: globalSettingsState.settings, globalSettings: globalSettingsState.settings,
); );
}, },
child: const Image(
image: AssetImage('assets/ui/button_start.png'),
fit: BoxFit.fill,
),
); );
}, },
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment