Skip to content

Commit 502be15

Browse files
committed
fix: исправление ошибки, при которой в локальную бд записывались локализированные данные
1 parent 30bd629 commit 502be15

7 files changed

Lines changed: 53 additions & 149 deletions

File tree

frontend/lib/views/game_view/components/shared_functions.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@ import 'package:sqflite/sqflite.dart';
33
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
44
import '../../../exports.dart';
55

6-
String getResultForHistory(GameModel gameModel, AppLocalizations l10n) {
6+
enum GameResult { draw, blackVictory, whiteVictory }
7+
8+
String getResultForHistory(GameModel gameModel) {
79
if (gameModel.gameOver) {
810
if (gameModel.stalemate || gameModel.draw) {
9-
return l10n.draw;
11+
return GameResult.draw.name;
1012
} else {
1113
if (gameModel.turn == Player.player1) {
12-
return l10n.blackVictory;
14+
return GameResult.blackVictory.name;
1315
} else {
14-
return l10n.whiteVictory;
16+
return GameResult.whiteVictory.name;
1517
}
1618
}
1719
} else {
18-
return l10n.draw;
20+
return GameResult.draw.name;
1921
}
2022
}
2123

2224
List<String> getPartyData(GameModel gameModel, AppLocalizations l10n) {
23-
String enemy = gameModel.playerCount == 1 ? l10n.computer : l10n.friend;
25+
String enemy = l10n.friend;
2426
String formattedDate = DateFormat("dd.MM.yyyy").format(DateTime.now());
2527
String formattedTime = DateFormat.Hm().format(DateTime.now());
2628
String durationGame = _formatDuration(gameModel.durationOfGame);
27-
String result = getResultForHistory(gameModel, l10n);
29+
String result = getResultForHistory(gameModel);
2830
String color = gameModel.playerSide == Player.player1
2931
? l10n.whitePieces
3032
: l10n.blackPieces;

frontend/lib/views/game_view/constants/game_page_const.dart

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,4 @@ class GamePageConst {
77
static const startPos =
88
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
99
static List<String> listOfColumns = ["h", "g", "f", "e", "d", "c", "b", "a"];
10-
static const gameStatusEnemyMove = "Ход противника ";
11-
static const gameStatusOurMove = "Ваш ход";
12-
static const gameStatusWhiteMove = "Ход белых";
13-
static const gameStatusBlackMove = "Ход чёрных";
14-
static const gameStatusStalemate = "Пат (Ничья)";
15-
static const gameStatusDraw = "Ничья";
16-
static const gameStatusBlackWin = "Выиграли чёрные";
17-
static const gameStatusWhiteWin = "Выиграли белые";
18-
static const gameEndText = "В главное меню";
19-
static const continueGameText = "Продолжить игру";
20-
static const gameRestartText = "Новая игра";
21-
static const gameGiveUpText = "Сдаться";
22-
static const gameBackModalHeader = "Сдаться?";
23-
static const gameResultWin = "Победа";
24-
static const gameResultLose = "Поражение";
25-
static const gameResultWinBlack = "Победа чёрных";
26-
static const gameResultWinWhite = "Победа белых";
2710
}

frontend/lib/views/party_history_view/components/info_bar_item.dart

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,28 @@ import 'package:flutter_svg/svg.dart';
33
import 'package:frontend/exports.dart';
44

55
class InfoBarItem extends StatelessWidget {
6-
const InfoBarItem({super.key, required this.index, required this.isComputer});
6+
const InfoBarItem({super.key, required this.text, required this.iconColor});
77

8-
final int index;
9-
final bool isComputer;
8+
final String text;
9+
final Color iconColor;
1010

1111
@override
1212
Widget build(BuildContext context) {
13-
final scheme = Theme.of(context).colorScheme;
14-
List<Color> computerColors = [
15-
scheme.onSecondaryContainer,
16-
scheme.primary,
17-
ColorsConst.secondaryColor100
18-
];
19-
20-
List<Color> friendColors = [
21-
scheme.primaryContainer,
22-
scheme.onSecondary,
23-
scheme.onSurface
24-
];
25-
2613
return Row(
2714
children: <Widget>[
2815
SvgPicture.asset(
2916
PartyHistoryConst.infoPartyIconName,
3017
height: 24,
3118
width: 24,
32-
colorFilter: ColorFilter.mode(
33-
isComputer ? computerColors[index] : friendColors[index],
34-
BlendMode.srcIn),
19+
colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn),
3520
),
3621
const SizedBox(
3722
width: 4,
3823
),
3924
Text(
40-
isComputer
41-
? PartyHistoryConst.gameResults[index]
42-
: PartyHistoryConst.friendGameResults[index],
25+
text,
4326
style: TextStyles.caption2.copyWith(
44-
color: scheme.primary,
27+
color: Theme.of(context).colorScheme.primary,
4528
height: 0.09,
4629
),
4730
),
Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import 'package:flutter/material.dart';
22
import 'package:frontend/exports.dart';
3+
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
34

45
class InfoPartyBar extends StatelessWidget {
56
const InfoPartyBar({
67
super.key,
78
required this.height,
8-
required this.isComputer,
99
});
1010

1111
final double height;
12-
final bool isComputer;
1312

1413
@override
1514
Widget build(BuildContext context) {
1615
final scheme = Theme.of(context).colorScheme;
17-
16+
final l10n = AppLocalizations.of(context);
1817
return Container(
1918
height: height,
2019
width: double.infinity,
@@ -23,49 +22,33 @@ class InfoPartyBar extends StatelessWidget {
2322
decoration: BoxDecoration(
2423
color: scheme.onSurfaceVariant,
2524
borderRadius: BorderRadius.circular(16)),
26-
child: isComputer
27-
? Row(
28-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
29-
mainAxisSize: MainAxisSize.min,
30-
children: List.generate(PartyHistoryConst.gameResults.length,
31-
(index) {
32-
return Row(
33-
children: [
34-
InfoBarItem(
35-
index: index,
36-
isComputer: isComputer,
37-
),
38-
],
39-
);
40-
}),
41-
)
42-
: Column(
43-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
44-
children: [
45-
Row(
46-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
47-
children: [
48-
InfoBarItem(
49-
index: 0,
50-
isComputer: isComputer,
51-
),
52-
const SizedBox(),
53-
InfoBarItem(
54-
index: 1,
55-
isComputer: isComputer,
56-
)
57-
],
58-
),
59-
Row(
60-
mainAxisAlignment: MainAxisAlignment.center,
61-
children: [
62-
InfoBarItem(
63-
index: 2,
64-
isComputer: isComputer,
65-
),
66-
],
67-
)
68-
],
69-
));
25+
child: Column(
26+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
27+
children: [
28+
Row(
29+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
30+
children: [
31+
InfoBarItem(
32+
text: l10n.whiteVictory,
33+
iconColor: scheme.primaryContainer,
34+
),
35+
const SizedBox(),
36+
InfoBarItem(
37+
text: l10n.blackVictory,
38+
iconColor: scheme.onSecondary,
39+
)
40+
],
41+
),
42+
Row(
43+
mainAxisAlignment: MainAxisAlignment.center,
44+
children: [
45+
InfoBarItem(
46+
text: l10n.draw,
47+
iconColor: scheme.onSurface,
48+
),
49+
],
50+
)
51+
],
52+
));
7053
}
7154
}

frontend/lib/views/party_history_view/components/one_party_view_widget.dart

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@ import 'package:frontend/exports.dart';
44
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
55

66
class OnePartyViewWidget extends StatelessWidget {
7-
const OnePartyViewWidget(
8-
{super.key, required this.partyData, required this.isComputer});
7+
const OnePartyViewWidget({super.key, required this.partyData});
98

109
final Map partyData;
11-
final bool isComputer;
1210

1311
@override
1412
Widget build(BuildContext context) {
1513
final scheme = Theme.of(context).colorScheme;
1614
final l10n = AppLocalizations.of(context);
17-
Map<String, Color> computerListOfColorsIcons = {
18-
l10n.victory: scheme.onSecondaryContainer,
19-
l10n.defeat: scheme.primary,
20-
l10n.draw: ColorsConst.secondaryColor100
21-
};
2215

2316
Map<String, Color> friendListOfColorsIcons = {
24-
l10n.whiteVictory: scheme.primaryContainer,
25-
l10n.blackVictory: scheme.onSecondary,
26-
l10n.draw: scheme.onSurface
17+
GameResult.whiteVictory.name: scheme.primaryContainer,
18+
GameResult.blackVictory.name: scheme.onSecondary,
19+
GameResult.draw.name: scheme.onSurface
2720
};
2821
return Container(
2922
margin: const EdgeInsets.only(bottom: 12, left: 24, right: 24),
@@ -36,9 +29,8 @@ class OnePartyViewWidget extends StatelessWidget {
3629
height: 35,
3730
width: 35,
3831
colorFilter: ColorFilter.mode(
39-
isComputer
40-
? computerListOfColorsIcons[partyData["result"]]!
41-
: friendListOfColorsIcons[partyData["result"]]!,
32+
friendListOfColorsIcons[partyData["result"]] ??
33+
ColorsConst.disabledColor,
4234
BlendMode.srcIn),
4335
),
4436
const SizedBox(
@@ -68,9 +60,7 @@ class OnePartyViewWidget extends StatelessWidget {
6860
child: Row(
6961
children: [
7062
Column(
71-
mainAxisAlignment: isComputer
72-
? MainAxisAlignment.spaceBetween
73-
: MainAxisAlignment.center,
63+
mainAxisAlignment: MainAxisAlignment.center,
7464
crossAxisAlignment: CrossAxisAlignment.end,
7565
children: [
7666
Text(
@@ -82,23 +72,12 @@ class OnePartyViewWidget extends StatelessWidget {
8272
height: 1,
8373
),
8474
),
85-
isComputer
86-
? Text(
87-
l10n.pieceColor,
88-
style: TextStyles.caption1.copyWith(
89-
color: scheme.error,
90-
height: 1,
91-
),
92-
)
93-
: const SizedBox(),
9475
],
9576
),
9677
SizedBox(
9778
width: 50,
9879
child: Column(
99-
mainAxisAlignment: isComputer
100-
? MainAxisAlignment.spaceBetween
101-
: MainAxisAlignment.center,
80+
mainAxisAlignment: MainAxisAlignment.center,
10281
crossAxisAlignment: CrossAxisAlignment.end,
10382
children: [
10483
partyData["durationGame"] != "00:00"
@@ -110,18 +89,6 @@ class OnePartyViewWidget extends StatelessWidget {
11089
),
11190
)
11291
: const SizedBox(),
113-
isComputer
114-
? Container(
115-
width: 12,
116-
height: 12,
117-
margin: const EdgeInsets.only(right: 4),
118-
decoration: BoxDecoration(
119-
borderRadius: BorderRadius.circular(50),
120-
color: partyData["color"] == l10n.whitePieces
121-
? scheme.inverseSurface
122-
: ColorsConst.neutralColor100),
123-
)
124-
: const SizedBox()
12592
],
12693
),
12794
)

frontend/lib/views/party_history_view/constants/party_history_const.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
class PartyHistoryConst {
2-
static String partyHistoryHeader = "История партий";
3-
42
static String appbarIconName = "assets/images/icons/left_big_arrow_icon.svg";
53

64
static String appbarMainIcon = "assets/images/icons/cancel.svg";
75

86
static String infoPartyIconName = "assets/images/icons/black.svg";
97

10-
static List<String> gameResults = ["Победа", "Поражение", "Ничья"];
11-
12-
static List<String> friendGameResults = [
13-
"Победа белых",
14-
"Победа чёрных",
15-
"Ничья"
16-
];
17-
18-
static List<String> gameEnemies = ["Компьютер", "Друг"];
19-
208
static String dbCreateScript = """CREATE TABLE History (
219
id INTEGER PRIMARY KEY,
2210
enemy STRING,

frontend/lib/views/party_history_view/party_history_main_view.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class _PartyHistoryMainViewState extends State<PartyHistoryMainView> {
6565
children: [
6666
InfoPartyBar(
6767
height: 80,
68-
isComputer: false,
6968
),
7069
SizedBox(height: 24),
7170
],
@@ -76,7 +75,6 @@ class _PartyHistoryMainViewState extends State<PartyHistoryMainView> {
7675
itemCount: friendParties.length,
7776
itemBuilder: (context, index) {
7877
return OnePartyViewWidget(
79-
isComputer: false,
8078
partyData: friendParties[index],
8179
);
8280
},

0 commit comments

Comments
 (0)