Skip to content

Commit 027fab5

Browse files
committed
refactor: исправления по код ревью
1 parent ed2ebf5 commit 027fab5

10 files changed

Lines changed: 136 additions & 245 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'package:flutter/material.dart';
2+
3+
sealed class SharedFunctions {
4+
static bool isTablet(BuildContext context) {
5+
final shortestSide = MediaQuery.of(context).size.shortestSide;
6+
return shortestSide >= 640;
7+
}
8+
}

frontend/lib/router/router.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ final shellRoutes = [
6969
path: RouteLocations.settingsScreen,
7070
parentNavigatorKey: shellNavigatorKey,
7171
builder: (BuildContext context, GoRouterState state) {
72-
return GameSettingsView(state.extra as GameModel);
72+
return GameSettingsView(
73+
state.extra as GameModel,
74+
key: gameSettingsViewStateKey,
75+
);
7376
},
7477
),
7578
GoRoute(

frontend/lib/views/components/pro_functions_tooltip.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ class ProFunctionsTooltip extends StatefulWidget {
1010
required this.modalHeader,
1111
required this.child,
1212
required this.isPro,
13-
this.controller,
1413
});
1514

1615
final String modalHeader;
1716
final Widget child;
1817
final bool isPro;
19-
final SuperTooltipController? controller;
2018

2119
@override
2220
State<ProFunctionsTooltip> createState() => _ProFunctionsTooltipState();
@@ -28,7 +26,13 @@ class _ProFunctionsTooltipState extends State<ProFunctionsTooltip> {
2826
@override
2927
void initState() {
3028
super.initState();
31-
_controller = widget.controller ?? SuperTooltipController();
29+
_controller = SuperTooltipController();
30+
}
31+
32+
@override
33+
void dispose() {
34+
_controller.dispose();
35+
super.dispose();
3236
}
3337

3438
@override
@@ -46,7 +50,7 @@ class _ProFunctionsTooltipState extends State<ProFunctionsTooltip> {
4650
popupDirection: TooltipDirection.up,
4751
content: DecoratedBox(
4852
decoration: BoxDecoration(
49-
borderRadius: BorderRadius.circular(16), color: Colors.white),
53+
borderRadius: BorderRadius.circular(16), color: Colors.white),
5054
child: Padding(
5155
padding: const EdgeInsets.symmetric(vertical: 24, horizontal: 32),
5256
child: Column(

frontend/lib/views/setting_view/components/app_bar_settings.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import "package:flutter/material.dart";
2+
import "package:frontend/common/shared_functions.dart";
23
import "package:go_router/go_router.dart";
34
import "../../../exports.dart";
45

56
class AppBarSettings extends StatelessWidget {
67
const AppBarSettings({super.key, required this.label});
78

89
final String label;
9-
bool _isTablet(BuildContext context) {
10-
final shortestSide = MediaQuery.of(context).size.shortestSide;
11-
return shortestSide > 640;
12-
}
1310

1411
@override
1512
Widget build(BuildContext context) {
1613
final scheme = Theme.of(context).colorScheme;
17-
final isTablet = _isTablet(context);
14+
final isTablet = SharedFunctions.isTablet(context);
1815
return Row(
1916
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2017
children: [

frontend/lib/views/setting_view/components/settings_row.dart

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import "package:flutter/material.dart";
22
import "package:flutter_svg/flutter_svg.dart";
3+
import "package:frontend/common/shared_functions.dart";
34
import "package:frontend/exports.dart";
45
import "package:provider/provider.dart";
5-
import "package:super_tooltip/super_tooltip.dart";
66

77
class SettingsRow extends StatefulWidget {
88
const SettingsRow({
@@ -12,44 +12,24 @@ class SettingsRow extends StatefulWidget {
1212
required this.modalHeader,
1313
this.choseDiffWidget,
1414
this.onChanged,
15-
this.forceTabletLayout,
1615
});
1716

1817
final bool? chose;
1918
final String text;
2019
final String modalHeader;
2120
final Widget? choseDiffWidget;
2221
final void Function(bool)? onChanged;
23-
final bool? forceTabletLayout;
2422

2523
@override
2624
State<SettingsRow> createState() => _SettingsRowState();
2725
}
2826

2927
class _SettingsRowState extends State<SettingsRow> {
30-
late final SuperTooltipController _tooltipController;
31-
32-
@override
33-
void initState() {
34-
super.initState();
35-
_tooltipController = SuperTooltipController();
36-
}
37-
38-
@override
39-
void dispose() {
40-
_tooltipController.dispose();
41-
super.dispose();
42-
}
43-
44-
bool _isTablet(BuildContext context) {
45-
return widget.forceTabletLayout ?? MediaQuery.of(context).size.width >= 640;
46-
}
47-
4828
@override
4929
Widget build(BuildContext context) {
5030
final scheme = Theme.of(context).colorScheme;
5131
final isPro = context.watch<ProVersionProvider>().isPro;
52-
final isTablet = _isTablet(context);
32+
final isTablet = SharedFunctions.isTablet(context);
5333
return Padding(
5434
padding: const EdgeInsets.only(bottom: 8),
5535
child: SizedBox(
@@ -66,17 +46,14 @@ class _SettingsRowState extends State<SettingsRow> {
6646
fontSize: isTablet ? 25 : 16,
6747
),
6848
),
69-
SizedBox(
70-
width: isTablet ? 16 : 10
71-
),
49+
SizedBox(width: isTablet ? 16 : 10),
7250
ProFunctionsTooltip(
7351
isPro: isPro,
7452
modalHeader: widget.modalHeader,
75-
controller: _tooltipController,
7653
child: SvgPicture.asset(
7754
"assets/images/icons/question_icon.svg",
7855
colorFilter: ColorFilter.mode(
79-
isPro
56+
isPro
8057
? scheme.tertiaryContainer
8158
: ColorsConst.disabledColor,
8259
BlendMode.srcIn),
@@ -86,21 +63,20 @@ class _SettingsRowState extends State<SettingsRow> {
8663
),
8764
Theme(
8865
data: ThemeData(useMaterial3: false),
89-
child: Switch(
90-
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
91-
value: isPro ? widget.chose! : false,
92-
inactiveThumbColor:
93-
isPro ? scheme.surfaceTint : ColorsConst.disabledColor,
94-
inactiveTrackColor: scheme.outline,
95-
activeColor: scheme.inversePrimary,
96-
activeTrackColor: ColorsConst.primaryColor100,
97-
onChanged: (value) {
98-
if (isPro) {
99-
widget.onChanged?.call(value);
100-
} else {
101-
_tooltipController.showTooltip();
102-
}
103-
},
66+
child: ProFunctionsTooltip(
67+
isPro: isPro,
68+
modalHeader: widget.modalHeader,
69+
child: Switch(
70+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
71+
value: isPro ? widget.chose! : false,
72+
inactiveThumbColor:
73+
isPro ? scheme.surfaceTint : ColorsConst.disabledColor,
74+
inactiveTrackColor: scheme.outline,
75+
activeColor: scheme.inversePrimary,
76+
activeTrackColor: ColorsConst.primaryColor100,
77+
onChanged:
78+
isPro ? (value) => widget.onChanged?.call(value) : null,
79+
),
10480
),
10581
),
10682
],

frontend/lib/views/setting_view/components/settings_rows_section.dart

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
import 'package:flutter/material.dart';
2+
import 'package:frontend/common/shared_functions.dart';
23
import 'package:frontend/exports.dart';
34
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
45

56
class SettingsRowsSection extends StatelessWidget {
6-
const SettingsRowsSection(
7-
{super.key,
8-
required this.choseMoveBack,
9-
required this.moveBackOnChanged,
10-
required this.choseThreats,
11-
required this.threatsOnChanged,
12-
required this.choseHints,
13-
required this.hintsOnChanged});
14-
15-
final bool choseMoveBack;
16-
final void Function(bool)? moveBackOnChanged;
17-
final bool choseThreats;
18-
final void Function(bool)? threatsOnChanged;
19-
final bool choseHints;
20-
final void Function(bool)? hintsOnChanged;
21-
22-
bool _isTablet(BuildContext context) {
23-
final shortestSide = MediaQuery.of(context).size.shortestSide;
24-
return shortestSide >= 640;
25-
}
7+
const SettingsRowsSection({
8+
super.key,
9+
});
2610

2711
@override
2812
Widget build(BuildContext context) {
29-
final isTablet = _isTablet(context);
13+
final settingsState = gameSettingsViewStateKey.currentState;
3014
final l10n = AppLocalizations.of(context)!;
3115
return Column(
3216
crossAxisAlignment: CrossAxisAlignment.start,
@@ -38,30 +22,30 @@ class SettingsRowsSection extends StatelessWidget {
3822
l10n.gameSettings,
3923
style: TextStyles.title3.copyWith(
4024
color: Theme.of(context).colorScheme.primary,
41-
fontSize: isTablet ? 45 : null,
25+
fontSize: SharedFunctions.isTablet(context) ? 45 : null,
4226
),
4327
),
4428
),
4529
),
4630
Column(
4731
children: [
4832
SettingsRow(
49-
chose: choseMoveBack,
33+
chose: settingsState?.isMoveBack,
5034
text: l10n.undoMoves,
5135
modalHeader: l10n.undoMovesDescription,
52-
onChanged: moveBackOnChanged,
36+
onChanged: settingsState?.setIsMoveBack,
5337
),
5438
SettingsRow(
55-
chose: choseThreats,
39+
chose: settingsState?.isThreats,
5640
text: l10n.threats,
5741
modalHeader: l10n.threatsDescription,
58-
onChanged: threatsOnChanged,
42+
onChanged: settingsState?.setIsThreats,
5943
),
6044
SettingsRow(
61-
chose: choseHints,
45+
chose: settingsState?.isHints,
6246
text: l10n.hints,
6347
modalHeader: l10n.hintsDescription,
64-
onChanged: hintsOnChanged,
48+
onChanged: settingsState?.setIsHints,
6549
)
6650
],
6751
),

frontend/lib/views/setting_view/components/text_heading.dart

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
import "package:flutter/material.dart";
2+
import "package:frontend/common/shared_functions.dart";
23
import "package:frontend/exports.dart";
34

45
class TextHeading extends StatelessWidget {
5-
const TextHeading(
6-
{super.key,
7-
required this.text,
8-
required this.topMargin,
9-
required this.bottomMargin,
10-
this.style,
11-
});
6+
const TextHeading({
7+
super.key,
8+
required this.text,
9+
required this.topMargin,
10+
required this.bottomMargin,
11+
this.style,
12+
});
1213

1314
final String text;
1415
final double topMargin;
1516
final double bottomMargin;
1617
final TextStyle? style;
1718

18-
bool _isTablet(BuildContext context) {
19-
final shortestSide = MediaQuery.of(context).size.shortestSide;
20-
return shortestSide >= 640;
21-
}
22-
2319
@override
2420
Widget build(BuildContext context) {
25-
final scheme = Theme.of(context).colorScheme;
26-
final isTablet = _isTablet(context);
2721
return Container(
2822
margin: EdgeInsets.only(top: topMargin, bottom: bottomMargin),
2923
child: Text(
3024
text,
3125
style: TextStyles.title3.copyWith(
32-
color: scheme.primary,
33-
fontSize: isTablet ? 45 : TextStyles.title3.fontSize,
26+
color: Theme.of(context).colorScheme.primary,
27+
fontSize: SharedFunctions.isTablet(context)
28+
? 45
29+
: TextStyles.title3.fontSize,
3430
),
3531
),
3632
);

0 commit comments

Comments
 (0)