flutter: settings: Support Font Size

This commit is contained in:
Calcitem 2021-06-01 01:12:09 +08:00
parent 62f8b4f2c7
commit 194b461788
14 changed files with 209 additions and 45 deletions

View File

@ -50,6 +50,7 @@ class Config {
static double boardBorderLineWidth = 2.0;
static double boardInnerLineWidth = 2.0;
static double pieceWidth = 0.9;
static double fontSize = 16.0;
static double boardTop = 36.0;
static double animationDuration = 0.0;
@ -108,6 +109,7 @@ class Config {
Config.boardBorderLineWidth = settings['BoardBorderLineWidth'] ?? 2;
Config.boardInnerLineWidth = settings['BoardInnerLineWidth'] ?? 2;
Config.pieceWidth = settings['PieceWidth'] ?? 0.9;
Config.fontSize = settings['FontSize'] ?? 16.0;
Config.boardTop = settings['BoardTop'] ?? 36;
Config.animationDuration = settings['AnimationDuration'] ?? 0;
@ -182,6 +184,7 @@ class Config {
settings['BoardBorderLineWidth'] = Config.boardBorderLineWidth;
settings['BoardInnerLineWidth'] = Config.boardInnerLineWidth;
settings['PieceWidth'] = Config.pieceWidth;
settings['FontSize'] = Config.fontSize;
settings['BoardTop'] = Config.boardTop;
settings['AnimationDuration'] = Config.animationDuration;

View File

@ -632,6 +632,10 @@
"@pieceWidth": {
"description": "Board inner line width"
},
"fontSize": "Schriftgröße",
"@fontSize": {
"description": "Font size"
},
"standardNotation": "Standardnotation",
"@standardNotation": {
"description": "Standard notation"

View File

@ -632,6 +632,10 @@
"@pieceWidth": {
"description": "Piece width"
},
"fontSize": "Font size",
"@fontSize": {
"description": "Font size"
},
"standardNotation": "Standard notation",
"@standardNotation": {
"description": "Standard notation"

View File

@ -158,6 +158,7 @@
"boardBorderLineWidth": "棋盘外框线宽",
"boardInnerLineWidth": "棋盘内部线宽",
"pieceWidth": "棋子大小",
"fontSize": "字体大小",
"standardNotation": "标准棋谱格式",
"restore": "重置",
"restoreDefaultSettings": "恢复默认设置",

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/style/colors.dart';
class AppTheme {
@ -94,29 +95,26 @@ class AppTheme {
valueIndicatorTextStyle: TextStyle(fontSize: 24),
);
// Style
static const colorizeTextStyle = TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.w600,
);
static var simpleDialogOptionTextStyle = TextStyle(
fontSize: AppTheme.simpleDialogOptionFontSize,
fontSize: Config.fontSize + 4.0,
color: AppTheme.simpleDialogOptionTextColor,
);
static var moveHistoryTextStyle =
TextStyle(fontSize: 18, height: 1.5, color: moveHistoryTextColor);
static var moveHistoryTextStyle = TextStyle(
fontSize: Config.fontSize + 2.0,
height: 1.5,
color: moveHistoryTextColor);
static double simpleDialogOptionFontSize = 20.0;
static double boardTop = 28.0;
static double boardMargin = 10.0;
static double boardScreenPaddingH = 10.0;
static double boardBorderRadius = 5.0;
static double boardPadding = 5.0;
static const settingsHeaderStyle =
TextStyle(color: settingsHeaderTextColor, fontSize: 20.0);
static var settingsHeaderStyle =
TextStyle(color: settingsHeaderTextColor, fontSize: Config.fontSize + 4);
static var settingsTextStyle = TextStyle(fontSize: Config.fontSize);
static const cardMargin =
const EdgeInsets.symmetric(vertical: 4.0, horizontal: 0);

View File

@ -22,6 +22,7 @@ import 'package:devicelocale/devicelocale.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/generated/flutter_version.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/style/app_theme.dart';

View File

@ -23,6 +23,7 @@ import 'package:devicelocale/devicelocale.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:url_launcher/url_launcher.dart';
@ -77,7 +78,7 @@ void showCountdownDialog(
S.of(ctx).cancel,
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontSize: Config.fontSize,
fontWeight: FontWeight.bold,
),
)),

View File

@ -545,7 +545,10 @@ class _GamePageState extends State<GamePage>
builder: (context) => AlertDialog(
title: Text(
S.of(context).appName,
style: TextStyle(color: AppTheme.dialogTitleColor),
style: TextStyle(
color: AppTheme.dialogTitleColor,
fontSize: Config.fontSize + 4,
),
),
content: Column(
mainAxisSize: MainAxisSize.min,
@ -553,12 +556,20 @@ class _GamePageState extends State<GamePage>
children: <Widget>[
Text(
S.of(context).experimental,
style: TextStyle(
fontSize: Config.fontSize,
),
),
],
),
actions: <Widget>[
TextButton(
child: Text(S.of(context).ok),
child: Text(
S.of(context).ok,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: () => Navigator.of(context).pop(),
),
],
@ -813,7 +824,10 @@ class _GamePageState extends State<GamePage>
return AlertDialog(
backgroundColor: AppTheme.moveHistoryDialogBackgroundColor,
title: Text(S.of(context).moveList,
style: TextStyle(color: AppTheme.moveHistoryTextColor)),
style: TextStyle(
color: AppTheme.moveHistoryTextColor,
fontSize: Config.fontSize + 2.0,
)),
content: SingleChildScrollView(
child:
Text(moveHistoryText, style: AppTheme.moveHistoryTextStyle)),
@ -996,11 +1010,24 @@ class _GamePageState extends State<GamePage>
builder: (BuildContext context) {
return AlertDialog(
title: Text(dialogTitle,
style: TextStyle(color: AppTheme.dialogTitleColor)),
content: Text(contentStr),
style: TextStyle(
color: AppTheme.dialogTitleColor,
fontSize: Config.fontSize + 4,
)),
content: Text(
contentStr,
style: TextStyle(
fontSize: Config.fontSize,
),
),
actions: <Widget>[
TextButton(
child: Text(S.of(context).yes),
child: Text(
S.of(context).yes,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: () {
if (!isTopLevel) Config.skillLevel++;
Config.save();
@ -1008,7 +1035,12 @@ class _GamePageState extends State<GamePage>
Navigator.of(context).pop();
}),
TextButton(
child: Text(S.of(context).no),
child: Text(
S.of(context).no,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: () => Navigator.of(context).pop()),
],
);
@ -1021,13 +1053,25 @@ class _GamePageState extends State<GamePage>
builder: (BuildContext context) {
return AlertDialog(
title: Text(dialogTitle,
style: TextStyle(color: AppTheme.dialogTitleColor)),
content: Text(getGameOverReasonString(
Game.instance.position.gameOverReason,
Game.instance.position.winner)),
style: TextStyle(
color: AppTheme.dialogTitleColor,
fontSize: Config.fontSize + 4,
)),
content: Text(
getGameOverReasonString(Game.instance.position.gameOverReason,
Game.instance.position.winner),
style: TextStyle(
fontSize: Config.fontSize,
),
),
actions: <Widget>[
TextButton(
child: Text(S.of(context).restart),
child: Text(
S.of(context).restart,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: () {
Navigator.of(context).pop();
Game.instance.newGame();
@ -1041,7 +1085,12 @@ class _GamePageState extends State<GamePage>
}
}),
TextButton(
child: Text(S.of(context).cancel),
child: Text(
S.of(context).cancel,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: () => Navigator.of(context).pop()),
],
);
@ -1115,7 +1164,8 @@ class _GamePageState extends State<GamePage>
child: Text(
_tip!,
maxLines: 1,
style: TextStyle(fontSize: 16, color: Color(Config.messageColor)),
style: TextStyle(
fontSize: Config.fontSize, color: Color(Config.messageColor)),
), // TODO: Font Size
),
],
@ -1176,7 +1226,12 @@ class _GamePageState extends State<GamePage>
{Duration duration = const Duration(milliseconds: 4000)}) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(message),
content: Text(
message,
style: TextStyle(
fontSize: Config.fontSize,
),
),
duration: duration,
));
}

View File

@ -128,13 +128,35 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
builder: (BuildContext context) {
return AlertDialog(
title: Text(S.of(context).restore,
style: TextStyle(color: AppTheme.dialogTitleColor)),
style: TextStyle(
color: AppTheme.dialogTitleColor,
fontSize: Config.fontSize + 4,
)),
content: SingleChildScrollView(
child: Text(S.of(context).restoreDefaultSettings + "?\n" + prompt),
child: Text(
S.of(context).restoreDefaultSettings + "?\n" + prompt,
style: TextStyle(
fontSize: Config.fontSize,
),
),
),
actions: <Widget>[
TextButton(child: Text(S.of(context).ok), onPressed: confirm),
TextButton(child: Text(S.of(context).cancel), onPressed: cancel),
TextButton(
child: Text(
S.of(context).ok,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: confirm),
TextButton(
child: Text(
S.of(context).cancel,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: cancel),
],
);
},

View File

@ -32,7 +32,7 @@ class _HelpScreenState extends State<HelpScreen> {
child: Text(
S.of(context).howToPlay,
style: TextStyle(
fontSize: 20,
fontSize: Config.fontSize + 4,
fontWeight: FontWeight.bold,
color: AppTheme.helpTextColor,
),
@ -45,7 +45,7 @@ class _HelpScreenState extends State<HelpScreen> {
S.of(context).helpContent,
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 16,
fontSize: Config.fontSize,
color: AppTheme.helpTextColor,
),
),

View File

@ -20,6 +20,7 @@ import 'dart:async';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/material.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/style/app_theme.dart';
import 'package:sanmill/widgets/game_settings_page.dart';
@ -140,7 +141,10 @@ class _HomeDrawerState extends State<HomeDrawer> {
animatedTexts: [
ColorizeAnimatedText(
S.of(context).appName,
textStyle: AppTheme.colorizeTextStyle,
textStyle: TextStyle(
fontSize: Config.fontSize + 16,
fontWeight: FontWeight.w600,
),
colors: AppTheme.animatedTextsColors,
textAlign: TextAlign.start,
speed: const Duration(milliseconds: 3000),
@ -302,7 +306,7 @@ class _HomeDrawerState extends State<HomeDrawer> {
listItem.title,
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
fontSize: Config.fontSize,
color: widget.screenIndex == listItem.index
? AppTheme.drawerHighlightTextColor
: AppTheme.drawerTextColor,

View File

@ -60,7 +60,12 @@ class _PersonalizationSettingsPageState
};
AlertDialog alert = AlertDialog(
title: Text(S.of(context).pick + " " + colorString),
title: Text(
S.of(context).pick + " " + colorString,
style: TextStyle(
fontSize: Config.fontSize + 4,
),
),
content: SingleChildScrollView(
child: ColorPicker(
pickerColor: Color(colorStrToVal[colorString]!),
@ -70,7 +75,12 @@ class _PersonalizationSettingsPageState
),
actions: <Widget>[
TextButton(
child: Text(S.of(context).confirm),
child: Text(
S.of(context).confirm,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: () {
setState(() => currentColor = pickerColor);
@ -95,7 +105,12 @@ class _PersonalizationSettingsPageState
},
),
TextButton(
child: Text(S.of(context).cancel),
child: Text(
S.of(context).cancel,
style: TextStyle(
fontSize: Config.fontSize,
),
),
onPressed: () {
Navigator.of(context).pop();
},
@ -205,6 +220,37 @@ class _PersonalizationSettingsPageState
);
}
SliderTheme _fontSizeSliderTheme(context, setState) {
return SliderTheme(
data: AppTheme.sliderThemeData,
child: Slider(
value: Config.fontSize.toDouble(),
min: 16,
max: 32,
divisions: 16,
label: Config.fontSize.toStringAsFixed(1),
onChanged: (value) {
setState(() {
print("[config] fontSize value: $value");
Config.fontSize = value;
Config.save();
});
},
),
);
}
setFontSize() async {
showModalBottomSheet(
context: context,
builder: (BuildContext context) => StatefulBuilder(
builder: (context, setState) {
return _fontSizeSliderTheme(context, setState);
},
),
);
}
SliderTheme _boardTopSliderTheme(context, setState) {
return SliderTheme(
data: AppTheme.sliderThemeData,
@ -322,6 +368,12 @@ class _PersonalizationSettingsPageState
onTap: setPieceWidth,
),
ListItemDivider(),
SettingsListTile(
context: context,
titleString: S.of(context).fontSize,
onTap: setFontSize,
),
ListItemDivider(),
SettingsListTile(
context: context,
titleString: S.of(context).boardTop,

View File

@ -17,6 +17,7 @@
*/
import 'package:flutter/material.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/style/app_theme.dart';
class SettingsListTile extends StatelessWidget {
@ -40,13 +41,21 @@ class SettingsListTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(titleString,
style: TextStyle(color: AppTheme.switchListTileTitleColor)),
title: Text(
titleString,
style: TextStyle(
fontSize: Config.fontSize,
color: AppTheme.switchListTileTitleColor,
),
),
subtitle: subtitleString == null
? null
: Text(
subtitleString!,
style: TextStyle(color: AppTheme.listTileSubtitleColor),
style: TextStyle(
fontSize: Config.fontSize,
color: AppTheme.listTileSubtitleColor,
),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
@ -56,6 +65,7 @@ class SettingsListTile extends StatelessWidget {
? (trailingString == null ? "" : trailingString!)
: trailingColor!.toRadixString(16),
style: TextStyle(
fontSize: Config.fontSize,
backgroundColor:
trailingColor == null ? null : Color(trailingColor!),
),

View File

@ -17,6 +17,7 @@
*/
import 'package:flutter/material.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/style/app_theme.dart';
class SettingsSwitchListTile extends StatelessWidget {
@ -41,13 +42,21 @@ class SettingsSwitchListTile extends StatelessWidget {
value: value,
onChanged: onChanged,
activeColor: AppTheme.switchListTileActiveColor,
title: Text(titleString,
style: TextStyle(color: AppTheme.switchListTileTitleColor)),
title: Text(
titleString,
style: TextStyle(
fontSize: Config.fontSize,
color: AppTheme.switchListTileTitleColor,
),
),
subtitle: subtitleString == null
? null
: Text(
subtitleString!,
style: TextStyle(color: AppTheme.listTileSubtitleColor),
style: TextStyle(
fontSize: Config.fontSize,
color: AppTheme.listTileSubtitleColor,
),
),
);
}