Skip to content

Commit dd16542

Browse files
authored
Merge pull request #76 from effectiveband/feature/settings-formatting
Вёрстка экрана настроек под форматы телефона и планшета
2 parents d70f3f9 + 5e5d470 commit dd16542

12 files changed

Lines changed: 490 additions & 312 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ 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+
gameModel: state.extra as GameModel,
74+
);
7375
},
7476
),
7577
GoRoute(

frontend/lib/views/components/pro_functions_tooltip.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ class ProFunctionsTooltip extends StatefulWidget {
2121
}
2222

2323
class _ProFunctionsTooltipState extends State<ProFunctionsTooltip> {
24-
final _controller = SuperTooltipController();
24+
late final SuperTooltipController _controller;
25+
26+
@override
27+
void initState() {
28+
super.initState();
29+
_controller = SuperTooltipController();
30+
}
31+
32+
@override
33+
void dispose() {
34+
_controller.dispose();
35+
super.dispose();
36+
}
2537

2638
@override
2739
Widget build(BuildContext context) {
@@ -62,14 +74,13 @@ class _ProFunctionsTooltipState extends State<ProFunctionsTooltip> {
6274
),
6375
),
6476
),
65-
!widget.isPro
66-
? UpgradeToProButton(
67-
onTap: () {
68-
_controller.hideTooltip();
69-
context.push(RouteLocations.promoScreen);
70-
},
71-
)
72-
: const SizedBox.shrink()
77+
if (!widget.isPro)
78+
UpgradeToProButton(
79+
onTap: () {
80+
_controller.hideTooltip();
81+
context.push(RouteLocations.promoScreen);
82+
},
83+
)
7384
],
7485
),
7586
),

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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

@@ -10,13 +11,14 @@ class AppBarSettings extends StatelessWidget {
1011
@override
1112
Widget build(BuildContext context) {
1213
final scheme = Theme.of(context).colorScheme;
14+
final isTablet = SharedFunctions.isTablet(context);
1315
return Row(
1416
mainAxisAlignment: MainAxisAlignment.spaceBetween,
1517
children: [
1618
CustomIconButton(
1719
iconName: "assets/images/icons/left_big_arrow_icon.svg",
1820
color: scheme.onTertiary,
19-
iconSize: 40,
21+
iconSize: isTablet ? 50 : 40,
2022
onTap: () {
2123
context.go(RouteLocations.homeScreen);
2224
},
@@ -25,12 +27,13 @@ class AppBarSettings extends StatelessWidget {
2527
label,
2628
style: TextStyles.body1.copyWith(
2729
color: scheme.primary,
30+
fontSize: isTablet ? 30 : 20,
2831
),
2932
),
3033
ButtonToGuide(
3134
backGroundColor: scheme.outlineVariant,
32-
height: 40,
33-
width: 40,
35+
height: isTablet ? 50 : 40,
36+
width: isTablet ? 50 : 40,
3437
onTap: () {
3538
context.push(RouteLocations.guidebookScreen);
3639
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class _ChoseTimeCarouselState extends State<ChoseTimeCarousel> {
4747
textAlign: TextAlign.center,
4848
style: TextStyles.header2.copyWith(
4949
color: scheme.primary,
50+
fontSize: MediaQuery.of(context).size.width > 640 ? 24 : 16,
5051
),
5152
),
5253
Center(

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
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";
56

6-
class SettingsRow extends StatelessWidget {
7+
class SettingsRow extends StatefulWidget {
78
const SettingsRow({
89
super.key,
910
this.chose,
@@ -19,10 +20,16 @@ class SettingsRow extends StatelessWidget {
1920
final Widget? choseDiffWidget;
2021
final void Function(bool)? onChanged;
2122

23+
@override
24+
State<SettingsRow> createState() => _SettingsRowState();
25+
}
26+
27+
class _SettingsRowState extends State<SettingsRow> {
2228
@override
2329
Widget build(BuildContext context) {
2430
final scheme = Theme.of(context).colorScheme;
2531
final isPro = context.watch<ProVersionProvider>().isPro;
32+
final isTablet = SharedFunctions.isTablet(context);
2633
return Padding(
2734
padding: const EdgeInsets.only(bottom: 8),
2835
child: SizedBox(
@@ -33,17 +40,16 @@ class SettingsRow extends StatelessWidget {
3340
Row(
3441
children: [
3542
Text(
36-
text,
43+
widget.text,
3744
style: TextStyles.body2.copyWith(
3845
color: isPro ? scheme.primary : ColorsConst.disabledColor,
46+
fontSize: isTablet ? 25 : 16,
3947
),
4048
),
41-
const SizedBox(
42-
width: 10,
43-
),
49+
SizedBox(width: isTablet ? 16 : 10),
4450
ProFunctionsTooltip(
4551
isPro: isPro,
46-
modalHeader: modalHeader,
52+
modalHeader: widget.modalHeader,
4753
child: SvgPicture.asset(
4854
"assets/images/icons/question_icon.svg",
4955
colorFilter: ColorFilter.mode(
@@ -57,17 +63,22 @@ class SettingsRow extends StatelessWidget {
5763
),
5864
Theme(
5965
data: ThemeData(useMaterial3: false),
60-
child: Switch(
61-
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
62-
value: isPro ? chose! : false,
63-
inactiveThumbColor:
64-
isPro ? scheme.surfaceTint : ColorsConst.disabledColor,
65-
inactiveTrackColor: scheme.outline,
66-
activeColor: scheme.inversePrimary,
67-
activeTrackColor: ColorsConst.primaryColor100,
68-
onChanged: onChanged,
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+
),
6980
),
70-
)
81+
),
7182
],
7283
),
7384
),

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

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
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';
5+
import 'package:frontend/views/setting_view/providers/game_settings_provider.dart';
6+
import 'package:provider/provider.dart';
47

58
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;
9+
const SettingsRowsSection({
10+
super.key,
11+
});
2112

2213
@override
2314
Widget build(BuildContext context) {
@@ -32,32 +23,34 @@ class SettingsRowsSection extends StatelessWidget {
3223
l10n.gameSettings,
3324
style: TextStyles.title3.copyWith(
3425
color: Theme.of(context).colorScheme.primary,
26+
fontSize: SharedFunctions.isTablet(context) ? 45 : null,
3527
),
3628
),
3729
),
3830
),
39-
Column(
40-
children: [
41-
SettingsRow(
42-
chose: choseMoveBack,
43-
text: l10n.undoMoves,
44-
modalHeader: l10n.undoMovesDescription,
45-
onChanged: moveBackOnChanged,
46-
),
47-
SettingsRow(
48-
chose: choseThreats,
49-
text: l10n.threats,
50-
modalHeader: l10n.threatsDescription,
51-
onChanged: threatsOnChanged,
52-
),
53-
SettingsRow(
54-
chose: choseHints,
55-
text: l10n.hints,
56-
modalHeader: l10n.hintsDescription,
57-
onChanged: hintsOnChanged,
58-
)
59-
],
60-
),
31+
Consumer<GameSettingsProvider>(
32+
builder: (_, provider, __) => Column(
33+
children: [
34+
SettingsRow(
35+
chose: provider.isMoveBack,
36+
text: l10n.undoMoves,
37+
modalHeader: l10n.undoMovesDescription,
38+
onChanged: provider.setIsMoveBack,
39+
),
40+
SettingsRow(
41+
chose: provider.isThreats,
42+
text: l10n.threats,
43+
modalHeader: l10n.threatsDescription,
44+
onChanged: provider.setIsThreats,
45+
),
46+
SettingsRow(
47+
chose: provider.isHints,
48+
text: l10n.hints,
49+
modalHeader: l10n.hintsDescription,
50+
onChanged: provider.setIsHints,
51+
)
52+
],
53+
)),
6154
],
6255
);
6356
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +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});
6+
const TextHeading({
7+
super.key,
8+
required this.text,
9+
required this.topMargin,
10+
required this.bottomMargin,
11+
this.style,
12+
});
1013

1114
final String text;
1215
final double topMargin;
1316
final double bottomMargin;
17+
final TextStyle? style;
1418

1519
@override
1620
Widget build(BuildContext context) {
17-
final scheme = Theme.of(context).colorScheme;
1821
return Container(
1922
margin: EdgeInsets.only(top: topMargin, bottom: bottomMargin),
2023
child: Text(
2124
text,
2225
style: TextStyles.title3.copyWith(
23-
color: scheme.primary,
26+
color: Theme.of(context).colorScheme.primary,
27+
fontSize: SharedFunctions.isTablet(context)
28+
? 45
29+
: TextStyles.title3.fontSize,
2430
),
2531
),
2632
);

0 commit comments

Comments
 (0)