From 961aa6241b18bfc56b6b28d7b93edf2528461df7 Mon Sep 17 00:00:00 2001 From: Leptopoda Date: Sun, 10 Oct 2021 11:16:01 +0200 Subject: [PATCH] fix some stuff - remove unnecessary containers - bump linting version in pubspec.yml - make `isLargeScreen` and `isSmallScreen` a geter - add decimal points to double values - remove unused SizedBox - use const constructor where possible - remove residual code - fix help_screen AppBar - Fix historyNavToolbar padding fix styling of drawer - fix the padding of the drawer elements. cleanup settings - removes unused properties - fixes ListItemDivider height --- src/ui/flutter_app/lib/main.dart | 4 +- .../flutter_app/lib/screens/about_page.dart | 1 - src/ui/flutter_app/lib/screens/game_page.dart | 276 ++++++++---------- .../lib/screens/game_settings_page.dart | 31 +- .../flutter_app/lib/screens/help_screen.dart | 4 +- .../flutter_app/lib/screens/home_drawer.dart | 12 +- .../lib/screens/list_item_divider.dart | 1 + .../personalization_settings_page.dart | 6 - .../lib/screens/rule_settings_page.dart | 16 - .../lib/screens/settings/settings_card.dart | 2 - .../screens/settings/settings_list_tile.dart | 4 +- .../settings/settings_switch_list_tile.dart | 2 - .../flutter_app/lib/shared/common/config.dart | 10 +- .../lib/shared/common/constants.dart | 8 +- src/ui/flutter_app/lib/shared/dialog.dart | 4 +- .../lib/shared/theme/app_theme.dart | 5 +- src/ui/flutter_app/pubspec.yaml | 2 +- 17 files changed, 142 insertions(+), 246 deletions(-) diff --git a/src/ui/flutter_app/lib/main.dart b/src/ui/flutter_app/lib/main.dart index 4712d02c..9a1b9e52 100644 --- a/src/ui/flutter_app/lib/main.dart +++ b/src/ui/flutter_app/lib/main.dart @@ -96,7 +96,7 @@ Future main() async { [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown], ); - if (Platform.isAndroid && isLargeScreen()) { + if (Platform.isAndroid && isLargeScreen) { SystemChrome.setSystemUIOverlayStyle( const SystemUiOverlayStyle( statusBarColor: Colors.transparent, @@ -108,7 +108,7 @@ Future main() async { ); } - if (isSmallScreen()) { + if (isSmallScreen) { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); } } diff --git a/src/ui/flutter_app/lib/screens/about_page.dart b/src/ui/flutter_app/lib/screens/about_page.dart index 905f6c65..8b2ad500 100644 --- a/src/ui/flutter_app/lib/screens/about_page.dart +++ b/src/ui/flutter_app/lib/screens/about_page.dart @@ -34,7 +34,6 @@ import 'list_item_divider.dart'; import 'oss_license_page.dart'; class AboutPage extends StatelessWidget { - // String _version = ""; final String tag = "[about] "; String get mode { diff --git a/src/ui/flutter_app/lib/screens/game_page.dart b/src/ui/flutter_app/lib/screens/game_page.dart index eb6ced0c..3151c60e 100644 --- a/src/ui/flutter_app/lib/screens/game_page.dart +++ b/src/ui/flutter_app/lib/screens/game_page.dart @@ -49,12 +49,9 @@ import 'game_settings_page.dart'; double boardWidth = 0.0; class GamePage extends StatefulWidget { - static double boardMargin = AppTheme.boardMargin; - static double screenPaddingH = AppTheme.boardScreenPaddingH; - final EngineType engineType; - const GamePage(this.engineType); + const GamePage(this.engineType, {Key? key}) : super(key: key); @override _GamePageState createState() => _GamePageState(); @@ -64,6 +61,9 @@ class _GamePageState extends State with RouteAware, SingleTickerProviderStateMixin { final Engine _engine = NativeEngine(); + double screenPaddingH = AppTheme.boardScreenPaddingH; + final double boardMargin = AppTheme.boardMargin; + String? _tip = ''; bool isReady = false; bool isGoingToHistory = false; @@ -77,26 +77,9 @@ class _GamePageState extends State late AnimationController _animationController; late Animation animation; bool disposed = false; - bool ltr = true; + late final bool ltr; final String tag = "[game_page]"; - @override - void initState() { - debugPrint("$tag Engine type: ${widget.engineType}"); - - gameInstance.setWhoIsAi(widget.engineType); - - super.initState(); - gameInstance.init(); - _engine.startup(); - - timer = Timer.periodic(const Duration(microseconds: 100), (Timer t) { - _setReadyState(); - }); - - _initAnimation(); - } - Future _setReadyState() async { debugPrint("$tag Check if need to set Ready state..."); if (!isReady && mounted && Config.settingsLoaded) { @@ -124,9 +107,7 @@ class _GamePageState extends State begin: 1.27, // sqrt(1.618) = 1.272 end: 1.0, ).animate(_animationController) - ..addListener(() { - setState(() {}); - }); + ..addListener(() => setState(() {})); _animationController.addStatusListener((state) { if (state == AnimationStatus.completed || @@ -904,6 +885,44 @@ class _GamePageState extends State } void onMoveButtonPressed() { + final List _historyNavigation = [ + SimpleDialogOption( + onPressed: onTakeBackButtonPressed, + child: Text( + S.of(context).takeBack, + style: AppTheme.simpleDialogOptionTextStyle, + textAlign: TextAlign.center, + ), + ), + const SizedBox(height: AppTheme.sizedBoxHeight), + SimpleDialogOption( + onPressed: onStepForwardButtonPressed, + child: Text( + S.of(context).stepForward, + style: AppTheme.simpleDialogOptionTextStyle, + textAlign: TextAlign.center, + ), + ), + const SizedBox(height: AppTheme.sizedBoxHeight), + SimpleDialogOption( + onPressed: onTakeBackAllButtonPressed, + child: Text( + S.of(context).takeBackAll, + style: AppTheme.simpleDialogOptionTextStyle, + textAlign: TextAlign.center, + ), + ), + const SizedBox(height: AppTheme.sizedBoxHeight), + SimpleDialogOption( + onPressed: onStepForwardAllButtonPressed, + child: Text( + S.of(context).stepForwardAll, + style: AppTheme.simpleDialogOptionTextStyle, + textAlign: TextAlign.center, + ), + ), + const SizedBox(height: AppTheme.sizedBoxHeight), + ]; showModalBottomSheet( context: context, backgroundColor: Colors.transparent, @@ -912,50 +931,7 @@ class _GamePageState extends State child: SimpleDialog( backgroundColor: Colors.transparent, children: [ - if (!Config.isHistoryNavigationToolbarShown) - SimpleDialogOption( - onPressed: onTakeBackButtonPressed, - child: Text( - S.of(context).takeBack, - style: AppTheme.simpleDialogOptionTextStyle, - textAlign: TextAlign.center, - ), - ), - if (!Config.isHistoryNavigationToolbarShown) - const SizedBox(height: AppTheme.sizedBoxHeight), - if (!Config.isHistoryNavigationToolbarShown) - SimpleDialogOption( - onPressed: onStepForwardButtonPressed, - child: Text( - S.of(context).stepForward, - style: AppTheme.simpleDialogOptionTextStyle, - textAlign: TextAlign.center, - ), - ), - if (!Config.isHistoryNavigationToolbarShown) - const SizedBox(height: AppTheme.sizedBoxHeight), - if (!Config.isHistoryNavigationToolbarShown) - SimpleDialogOption( - onPressed: onTakeBackAllButtonPressed, - child: Text( - S.of(context).takeBackAll, - style: AppTheme.simpleDialogOptionTextStyle, - textAlign: TextAlign.center, - ), - ), - if (!Config.isHistoryNavigationToolbarShown) - const SizedBox(height: AppTheme.sizedBoxHeight), - if (!Config.isHistoryNavigationToolbarShown) - SimpleDialogOption( - onPressed: onStepForwardAllButtonPressed, - child: Text( - S.of(context).stepForwardAll, - style: AppTheme.simpleDialogOptionTextStyle, - textAlign: TextAlign.center, - ), - ), - if (!Config.isHistoryNavigationToolbarShown) - const SizedBox(height: AppTheme.sizedBoxHeight), + if (!Config.isHistoryNavigationToolbarShown) ..._historyNavigation, SimpleDialogOption( onPressed: onMoveListButtonPressed, child: Text( @@ -1430,21 +1406,23 @@ class _GamePageState extends State } } - void calcScreenPaddingH() { + double get _screenPaddingH { // // when screen's height/width rate is less than 16/9, limit width of board final windowSize = MediaQuery.of(context).size; final double height = windowSize.height; double width = windowSize.width; + // TODO: maybe use windowSize.aspectratio if (height / width < 16.0 / 9.0) { width = height * 9 / 16; - GamePage.screenPaddingH = - (windowSize.width - width) / 2 - AppTheme.boardMargin; + return (windowSize.width - width) / 2 - AppTheme.boardMargin; + } else { + return AppTheme.boardScreenPaddingH; } } - Widget createPageHeader() { + Widget get header { final Map engineTypeToIconLeft = { EngineType.humanVsAi: Config.aiMovesFirst ? FluentIcons.bot_24_filled @@ -1467,17 +1445,14 @@ class _GamePageState extends State EngineType.testViaLAN: FluentIcons.wifi_1_24_filled, }; - final IconData iconArrow = getIconArrow(); - final iconColor = Color(Config.messageColor); final iconRow = Row( + mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: SizedBox()), Icon(engineTypeToIconLeft[widget.engineType], color: iconColor), Icon(iconArrow, color: iconColor), Icon(engineTypeToIconRight[widget.engineType], color: iconColor), - const Expanded(child: SizedBox()), ], ); @@ -1511,7 +1486,7 @@ class _GamePageState extends State ); } - IconData getIconArrow() { + IconData get iconArrow { IconData iconArrow = FluentIcons.code_24_regular; if (gameInstance.position.phase == Phase.gameOver) { @@ -1547,15 +1522,11 @@ class _GamePageState extends State return iconArrow; } - Widget createBoard() { - boardWidth = - MediaQuery.of(context).size.width - GamePage.screenPaddingH * 2; + Widget get board { + boardWidth = MediaQuery.of(context).size.width - screenPaddingH * 2; return Container( - margin: EdgeInsets.symmetric( - horizontal: GamePage.screenPaddingH, - vertical: GamePage.boardMargin, - ), + margin: EdgeInsets.symmetric(vertical: boardMargin), child: Board( width: boardWidth, onBoardTap: onBoardTap, @@ -1630,7 +1601,7 @@ class _GamePageState extends State return ret; } - Widget createToolbar() { + Widget get toolbar { final gameButton = TextButton( onPressed: onGameButtonPressed, child: Column( @@ -1704,94 +1675,70 @@ class _GamePageState extends State borderRadius: BorderRadius.circular(5), color: Color(Config.mainToolbarBackgroundColor), ), - margin: EdgeInsets.symmetric(horizontal: GamePage.screenPaddingH), + margin: EdgeInsets.symmetric(horizontal: screenPaddingH), padding: const EdgeInsets.symmetric(vertical: 2), child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, textDirection: TextDirection.ltr, children: [ - const Expanded(child: SizedBox()), gameButton, - const Expanded(child: SizedBox()), optionsButton, - const Expanded(child: SizedBox()), moveButton, - const Expanded(child: SizedBox()), //dashboard_outlined infoButton, - const Expanded(child: SizedBox()), ], ), ); } - Widget createHistoryNavigationToolbar() { + Widget get historyNavToolbar { final takeBackAllButton = TextButton( - child: Column( - // Replace with a Row for horizontal icon + text - children: [ - Semantics( - label: S.of(context).takeBackAll, - child: Icon( - ltr - ? FluentIcons.arrow_previous_24_regular - : FluentIcons.arrow_next_24_regular, - color: Color(Config.navigationToolbarIconColor), - ), - ), - ], + child: Semantics( + label: S.of(context).takeBackAll, + child: Icon( + ltr + ? FluentIcons.arrow_previous_24_regular + : FluentIcons.arrow_next_24_regular, + color: Color(Config.navigationToolbarIconColor), + ), ), onPressed: () => onTakeBackAllButtonPressed(pop: false), ); final takeBackButton = TextButton( - child: Column( - // Replace with a Row for horizontal icon + text - children: [ - Semantics( - label: S.of(context).takeBack, - child: Icon( - ltr - ? FluentIcons.chevron_left_24_regular - : FluentIcons.chevron_right_24_regular, - color: Color(Config.navigationToolbarIconColor), - ), - ), - ], + child: Semantics( + label: S.of(context).takeBack, + child: Icon( + ltr + ? FluentIcons.chevron_left_24_regular + : FluentIcons.chevron_right_24_regular, + color: Color(Config.navigationToolbarIconColor), + ), ), onPressed: () => onTakeBackButtonPressed(pop: false), ); final stepForwardButton = TextButton( - child: Column( - // Replace with a Row for horizontal icon + text - children: [ - Semantics( - label: S.of(context).stepForward, - child: Icon( - ltr - ? FluentIcons.chevron_right_24_regular - : FluentIcons.chevron_left_24_regular, - color: Color(Config.navigationToolbarIconColor), - ), - ), - ], + child: Semantics( + label: S.of(context).stepForward, + child: Icon( + ltr + ? FluentIcons.chevron_right_24_regular + : FluentIcons.chevron_left_24_regular, + color: Color(Config.navigationToolbarIconColor), + ), ), onPressed: () => onStepForwardButtonPressed(pop: false), ); final stepForwardAllButton = TextButton( - child: Column( - // Replace with a Row for horizontal icon + text - children: [ - Semantics( - label: S.of(context).stepForwardAll, - child: Icon( - ltr - ? FluentIcons.arrow_next_24_regular - : FluentIcons.arrow_previous_24_regular, - color: Color(Config.navigationToolbarIconColor), - ), - ), - ], + child: Semantics( + label: S.of(context).stepForwardAll, + child: Icon( + ltr + ? FluentIcons.arrow_next_24_regular + : FluentIcons.arrow_previous_24_regular, + color: Color(Config.navigationToolbarIconColor), + ), ), onPressed: () => onStepForwardAllButtonPressed(pop: false), ); @@ -1801,25 +1748,41 @@ class _GamePageState extends State borderRadius: BorderRadius.circular(5), color: Color(Config.navigationToolbarBackgroundColor), ), - margin: EdgeInsets.symmetric(horizontal: GamePage.screenPaddingH), + margin: EdgeInsets.symmetric( + horizontal: screenPaddingH, + vertical: 1, + ), padding: const EdgeInsets.symmetric(vertical: 2), child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, textDirection: TextDirection.ltr, children: [ - const Expanded(child: SizedBox()), takeBackAllButton, - const Expanded(child: SizedBox()), takeBackButton, - const Expanded(child: SizedBox()), stepForwardButton, - const Expanded(child: SizedBox()), //dashboard_outlined stepForwardAllButton, - const Expanded(child: SizedBox()), ], ), ); } + @override + void initState() { + debugPrint("$tag Engine type: ${widget.engineType}"); + + gameInstance.setWhoIsAi(widget.engineType); + + super.initState(); + gameInstance.init(); + _engine.startup(); + + timer = Timer.periodic(const Duration(microseconds: 100), (Timer t) { + _setReadyState(); + }); + + _initAnimation(); + } + @override void didChangeDependencies() { super.didChangeDependencies(); @@ -1827,23 +1790,16 @@ class _GamePageState extends State this, ModalRoute.of(context)! as PageRoute, ); + screenPaddingH = _screenPaddingH; + ltr = getBidirectionality(context) == Bidirectionality.leftToRight; } @override Widget build(BuildContext context) { - ltr = getBidirectionality(context) == Bidirectionality.leftToRight; - if (_tip == '') { _tip = S.of(context).welcome; } - calcScreenPaddingH(); - - final header = createPageHeader(); - final board = createBoard(); - final toolbar = createToolbar(); - final historyNavToolbar = createHistoryNavigationToolbar(); - return Scaffold( backgroundColor: Color(Config.darkBackgroundColor), body: Column( diff --git a/src/ui/flutter_app/lib/screens/game_settings_page.dart b/src/ui/flutter_app/lib/screens/game_settings_page.dart index 0092b4e2..b78aaa09 100644 --- a/src/ui/flutter_app/lib/screens/game_settings_page.dart +++ b/src/ui/flutter_app/lib/screens/game_settings_page.dart @@ -194,10 +194,8 @@ class _GameSettingsPageState extends State { return [ Text(S.of(context).whoMovesFirst, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsSwitchListTile( - context: context, value: !Config.aiMovesFirst, onChanged: setWhoMovesFirst, titleString: @@ -208,7 +206,6 @@ class _GameSettingsPageState extends State { const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).difficulty, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsListTile( titleString: S.of(context).skillLevel, @@ -224,7 +221,6 @@ class _GameSettingsPageState extends State { const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).aisPlayStyle, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsListTile( titleString: S.of(context).algorithm, @@ -232,66 +228,50 @@ class _GameSettingsPageState extends State { onTap: setAlgorithm, ), SettingsSwitchListTile( - context: context, value: Config.drawOnHumanExperience, onChanged: setDrawOnHumanExperience, titleString: S.of(context).drawOnHumanExperience, ), SettingsSwitchListTile( - context: context, value: Config.considerMobility, onChanged: setConsiderMobility, titleString: S.of(context).considerMobility, ), SettingsSwitchListTile( - context: context, value: Config.aiIsLazy, onChanged: setAiIsLazy, titleString: S.of(context).passive, ), SettingsSwitchListTile( - context: context, value: Config.shufflingEnabled, onChanged: setShufflingEnabled, titleString: S.of(context).shufflingEnabled, ), ], ), + if (!Platform.isWindows) const SizedBox(height: AppTheme.sizedBoxHeight), if (!Platform.isWindows) - const SizedBox(height: AppTheme.sizedBoxHeight) - else - const SizedBox(height: 0.0, width: 0.0), - if (!Platform.isWindows) - Text(S.of(context).playSounds, style: AppTheme.settingsHeaderStyle) - else - const SizedBox(height: 0.0, width: 0.0), + Text(S.of(context).playSounds, style: AppTheme.settingsHeaderStyle), if (!Platform.isWindows) SettingsCard( - context: context, children: [ SettingsSwitchListTile( - context: context, value: Config.toneEnabled, onChanged: setTone, titleString: S.of(context).playSoundsInTheGame, ), SettingsSwitchListTile( - context: context, value: Config.keepMuteWhenTakingBack, onChanged: setKeepMuteWhenTakingBack, titleString: S.of(context).keepMuteWhenTakingBack, ), ], - ) - else - const SizedBox(height: 0.0, width: 0.0), + ), const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).accessibility, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsSwitchListTile( - context: context, value: Config.screenReaderSupport, onChanged: setScreenReaderSupport, titleString: S.of(context).screenReaderSupport, @@ -301,7 +281,6 @@ class _GameSettingsPageState extends State { const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).restore, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsListTile( titleString: S.of(context).restoreDefaultSettings, @@ -317,22 +296,18 @@ class _GameSettingsPageState extends State { ), if (Developer.developerModeEnabled) SettingsCard( - context: context, children: [ SettingsSwitchListTile( - context: context, value: Config.developerMode, onChanged: setDeveloperMode, titleString: S.of(context).developerMode, ), SettingsSwitchListTile( - context: context, value: Config.experimentsEnabled, onChanged: setExperimentsEnabled, titleString: S.of(context).experiments, ), SettingsSwitchListTile( - context: context, value: Config.isAutoRestart, onChanged: setIsAutoRestart, titleString: S.of(context).isAutoRestart, diff --git a/src/ui/flutter_app/lib/screens/help_screen.dart b/src/ui/flutter_app/lib/screens/help_screen.dart index 0130e7ee..de170302 100644 --- a/src/ui/flutter_app/lib/screens/help_screen.dart +++ b/src/ui/flutter_app/lib/screens/help_screen.dart @@ -8,12 +8,12 @@ class HelpScreen extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( + elevation: 0.0, + backgroundColor: Color(Config.darkBackgroundColor), centerTitle: true, title: Text( S.of(context).howToPlay, style: TextStyle( - fontSize: Config.fontSize + 4, - fontWeight: FontWeight.bold, color: AppTheme.helpTextColor, ), ), diff --git a/src/ui/flutter_app/lib/screens/home_drawer.dart b/src/ui/flutter_app/lib/screens/home_drawer.dart index 4c3fecdf..347b9f8e 100644 --- a/src/ui/flutter_app/lib/screens/home_drawer.dart +++ b/src/ui/flutter_app/lib/screens/home_drawer.dart @@ -186,7 +186,7 @@ class HomeDrawer extends StatelessWidget { children: [ animatedBuilder, Padding( - padding: EdgeInsets.only(top: isLargeScreen() ? 30 : 8, left: 4), + padding: EdgeInsets.only(top: isLargeScreen ? 30 : 8, left: 4), child: ExcludeSemantics(child: animatedTextKit), ), ], @@ -269,7 +269,7 @@ class HomeDrawer extends StatelessWidget { 0.0, ), child: Padding( - padding: const EdgeInsets.symmetric(vertical: 8), + padding: const EdgeInsets.symmetric(horizontal: 8), child: Container( width: MediaQuery.of(context).size.width * 0.75 - 64, height: 46, @@ -298,7 +298,7 @@ class HomeDrawer extends StatelessWidget { final stack = Stack( children: [ Padding( - padding: const EdgeInsets.symmetric(vertical: 8.0), + padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Row( children: [ const SizedBox(height: 46.0, width: 6.0), @@ -326,7 +326,7 @@ class HomeDrawer extends StatelessWidget { ], ), ), - if (screenIndex == listItem.index) animatedBuilder else const SizedBox() + if (screenIndex == listItem.index) animatedBuilder, ], ); @@ -336,9 +336,7 @@ class HomeDrawer extends StatelessWidget { child: InkWell( splashColor: AppTheme.drawerSplashColor, highlightColor: AppTheme.drawerHighlightColor, - onTap: () { - navigationToScreen(listItem.index); - }, + onTap: () => navigationToScreen(listItem.index), child: stack, ), ); diff --git a/src/ui/flutter_app/lib/screens/list_item_divider.dart b/src/ui/flutter_app/lib/screens/list_item_divider.dart index 3b80df82..55a22ff5 100644 --- a/src/ui/flutter_app/lib/screens/list_item_divider.dart +++ b/src/ui/flutter_app/lib/screens/list_item_divider.dart @@ -29,6 +29,7 @@ class ListItemDivider extends StatelessWidget { return Divider( indent: 16, endIndent: 16, + height: 1.0, thickness: 1.0, color: AppTheme.listItemDividerColor, ); diff --git a/src/ui/flutter_app/lib/screens/personalization_settings_page.dart b/src/ui/flutter_app/lib/screens/personalization_settings_page.dart index b5e289a9..330df6ec 100644 --- a/src/ui/flutter_app/lib/screens/personalization_settings_page.dart +++ b/src/ui/flutter_app/lib/screens/personalization_settings_page.dart @@ -387,7 +387,6 @@ class _PersonalizationSettingsPageState return [ Text(S.of(context).display, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsListTile( titleString: S.of(context).language, @@ -398,19 +397,16 @@ class _PersonalizationSettingsPageState onTap: () => setLanguage(context, langCallback), ), SettingsSwitchListTile( - context: context, value: Config.isPieceCountInHandShown, onChanged: setIsPieceCountInHandShown, titleString: S.of(context).isPieceCountInHandShown, ), SettingsSwitchListTile( - context: context, value: Config.isNotationsShown, onChanged: setIsNotationsShown, titleString: S.of(context).isNotationsShown, ), SettingsSwitchListTile( - context: context, value: Config.isHistoryNavigationToolbarShown, onChanged: setIsHistoryNavigationToolbarShown, titleString: S.of(context).isHistoryNavigationToolbarShown, @@ -440,7 +436,6 @@ class _PersonalizationSettingsPageState onTap: setAnimationDuration, ), SettingsSwitchListTile( - context: context, value: Config.standardNotationEnabled, onChanged: setStandardNotationEnabled, titleString: S.of(context).standardNotation, @@ -450,7 +445,6 @@ class _PersonalizationSettingsPageState const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).color, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsListTile( titleString: S.of(context).boardColor, diff --git a/src/ui/flutter_app/lib/screens/rule_settings_page.dart b/src/ui/flutter_app/lib/screens/rule_settings_page.dart index 05e25d10..ec2589c2 100644 --- a/src/ui/flutter_app/lib/screens/rule_settings_page.dart +++ b/src/ui/flutter_app/lib/screens/rule_settings_page.dart @@ -54,7 +54,6 @@ class _RuleSettingsPageState extends State { return [ Text(S.of(context).general, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsListTile( titleString: S.of(context).piecesCount, @@ -63,7 +62,6 @@ class _RuleSettingsPageState extends State { onTap: setNTotalPiecesEachSide, ), SettingsSwitchListTile( - context: context, value: Config.hasDiagonalLines, onChanged: setHasDiagonalLines, titleString: S.of(context).hasDiagonalLines, @@ -82,7 +80,6 @@ class _RuleSettingsPageState extends State { onTap: setEndgameNMoveRule, ), SettingsSwitchListTile( - context: context, value: Config.threefoldRepetitionRule, onChanged: setThreefoldRepetitionRule, titleString: S.of(context).threefoldRepetitionRule, @@ -93,17 +90,14 @@ class _RuleSettingsPageState extends State { const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).placing, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsSwitchListTile( - context: context, value: Config.hasBannedLocations, onChanged: setHasBannedLocations, titleString: S.of(context).hasBannedLocations, subtitleString: S.of(context).hasBannedLocations_Detail, ), SettingsSwitchListTile( - context: context, value: Config.isWhiteLoseButNotDrawWhenBoardFull, onChanged: setIsWhiteLoseButNotDrawWhenBoardFull, titleString: S.of(context).isWhiteLoseButNotDrawWhenBoardFull, @@ -111,7 +105,6 @@ class _RuleSettingsPageState extends State { S.of(context).isWhiteLoseButNotDrawWhenBoardFull_Detail, ), SettingsSwitchListTile( - context: context, value: Config.mayOnlyRemoveUnplacedPieceInPlacingPhase, onChanged: setMayOnlyRemoveUnplacedPieceInPlacingPhase, titleString: S.of(context).removeUnplacedPiece, @@ -122,11 +115,9 @@ class _RuleSettingsPageState extends State { const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).moving, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ if (Config.experimentsEnabled) SettingsSwitchListTile( - context: context, value: Config.mayMoveInPlacingPhase, onChanged: setMayMoveInPlacingPhase, titleString: S.of(context).mayMoveInPlacingPhase, @@ -134,14 +125,12 @@ class _RuleSettingsPageState extends State { ) else SettingsSwitchListTile( - context: context, value: Config.isDefenderMoveFirst, onChanged: setIsDefenderMoveFirst, titleString: S.of(context).isDefenderMoveFirst, subtitleString: S.of(context).isDefenderMoveFirst_Detail, ), SettingsSwitchListTile( - context: context, value: Config.isLoseButNotChangeSideWhenNoWay, onChanged: setIsLoseButNotChangeSideWhenNoWay, titleString: S.of(context).isLoseButNotChangeSideWhenNoWay, @@ -153,10 +142,8 @@ class _RuleSettingsPageState extends State { const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).mayFly, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsSwitchListTile( - context: context, value: Config.mayFly, onChanged: setAllowFlyingAllowed, titleString: S.of(context).mayFly, @@ -173,17 +160,14 @@ class _RuleSettingsPageState extends State { const SizedBox(height: AppTheme.sizedBoxHeight), Text(S.of(context).removing, style: AppTheme.settingsHeaderStyle), SettingsCard( - context: context, children: [ SettingsSwitchListTile( - context: context, value: Config.mayRemoveFromMillsAlways, onChanged: setAllowRemovePieceInMill, titleString: S.of(context).mayRemoveFromMillsAlways, subtitleString: S.of(context).mayRemoveFromMillsAlways_Detail, ), SettingsSwitchListTile( - context: context, value: Config.mayRemoveMultiple, onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill, titleString: S.of(context).mayRemoveMultiple, diff --git a/src/ui/flutter_app/lib/screens/settings/settings_card.dart b/src/ui/flutter_app/lib/screens/settings/settings_card.dart index efae523f..0debe7a1 100644 --- a/src/ui/flutter_app/lib/screens/settings/settings_card.dart +++ b/src/ui/flutter_app/lib/screens/settings/settings_card.dart @@ -23,11 +23,9 @@ import 'package:sanmill/shared/theme/app_theme.dart'; class SettingsCard extends StatelessWidget { const SettingsCard({ Key? key, - required this.context, required this.children, }) : super(key: key); - final BuildContext context; final List children; @override diff --git a/src/ui/flutter_app/lib/screens/settings/settings_list_tile.dart b/src/ui/flutter_app/lib/screens/settings/settings_list_tile.dart index acc419db..cf1d2c11 100644 --- a/src/ui/flutter_app/lib/screens/settings/settings_list_tile.dart +++ b/src/ui/flutter_app/lib/screens/settings/settings_list_tile.dart @@ -63,9 +63,7 @@ class SettingsListTile extends StatelessWidget { mainAxisSize: MainAxisSize.min, children: [ Text( - trailingColor == null - ? (trailingString == null ? "" : trailingString!) - : trailingColor!.toRadixString(16), + trailingColor?.toRadixString(16) ?? trailingString ?? '', style: TextStyle( fontSize: Config.fontSize, backgroundColor: diff --git a/src/ui/flutter_app/lib/screens/settings/settings_switch_list_tile.dart b/src/ui/flutter_app/lib/screens/settings/settings_switch_list_tile.dart index 34afbbcd..f4e58750 100644 --- a/src/ui/flutter_app/lib/screens/settings/settings_switch_list_tile.dart +++ b/src/ui/flutter_app/lib/screens/settings/settings_switch_list_tile.dart @@ -23,14 +23,12 @@ import 'package:sanmill/shared/theme/app_theme.dart'; class SettingsSwitchListTile extends StatelessWidget { const SettingsSwitchListTile({ Key? key, - required this.context, required this.value, required this.onChanged, required this.titleString, this.subtitleString, }) : super(key: key); - final BuildContext context; final bool value; final String titleString; final String? subtitleString; diff --git a/src/ui/flutter_app/lib/shared/common/config.dart b/src/ui/flutter_app/lib/shared/common/config.dart index 437b1038..c5a1b4f6 100644 --- a/src/ui/flutter_app/lib/shared/common/config.dart +++ b/src/ui/flutter_app/lib/shared/common/config.dart @@ -60,7 +60,7 @@ class Config { static double boardInnerLineWidth = 2.0; static double pieceWidth = 0.9; static double fontSize = 16.0; - static double boardTop = isLargeScreen() ? 75.0 : 36.0; + static double boardTop = isLargeScreen ? 75.0 : 36.0; static double animationDuration = 0.0; // Color @@ -146,14 +146,14 @@ class Config { Config.isHistoryNavigationToolbarShown = settings['IsHistoryNavigationToolbarShown'] as bool? ?? false; Config.boardBorderLineWidth = - settings['BoardBorderLineWidth'] as double? ?? 2; + settings['BoardBorderLineWidth'] as double? ?? 2.0; Config.boardInnerLineWidth = - settings['BoardInnerLineWidth'] as double? ?? 2; + settings['BoardInnerLineWidth'] as double? ?? 2.0; Config.pieceWidth = settings['PieceWidth'] as double? ?? 0.9; Config.fontSize = settings['FontSize'] as double? ?? 16.0; Config.boardTop = - settings['BoardTop'] as double? ?? (isLargeScreen() ? 75 : 36); - Config.animationDuration = settings['AnimationDuration'] as double? ?? 0; + settings['BoardTop'] as double? ?? (isLargeScreen ? 75.0 : 36.0); + Config.animationDuration = settings['AnimationDuration'] as double? ?? 0.0; // Color Config.boardLineColor = diff --git a/src/ui/flutter_app/lib/shared/common/constants.dart b/src/ui/flutter_app/lib/shared/common/constants.dart index 5f094e5a..5b1ef46a 100644 --- a/src/ui/flutter_app/lib/shared/common/constants.dart +++ b/src/ui/flutter_app/lib/shared/common/constants.dart @@ -78,10 +78,6 @@ class Constants { static final windowAspectRatio = windowHeight / windowWidth; } -bool isSmallScreen() { - return Constants.windowHeight <= 800; -} +bool get isSmallScreen => Constants.windowHeight <= 800; -bool isLargeScreen() { - return !isSmallScreen(); -} +bool get isLargeScreen => !isSmallScreen; diff --git a/src/ui/flutter_app/lib/shared/dialog.dart b/src/ui/flutter_app/lib/shared/dialog.dart index 9380567a..cb7b8c7a 100644 --- a/src/ui/flutter_app/lib/shared/dialog.dart +++ b/src/ui/flutter_app/lib/shared/dialog.dart @@ -189,9 +189,7 @@ Future showPrivacyDialog( setPrivacyPolicyAccepted(false); SystemChannels.platform.invokeMethod('SystemNavigator.pop'); }, - ) - else - const SizedBox(height: 0.0, width: 0.0), + ), ], ), ); diff --git a/src/ui/flutter_app/lib/shared/theme/app_theme.dart b/src/ui/flutter_app/lib/shared/theme/app_theme.dart index 921c3581..990a19dd 100644 --- a/src/ui/flutter_app/lib/shared/theme/app_theme.dart +++ b/src/ui/flutter_app/lib/shared/theme/app_theme.dart @@ -4,7 +4,8 @@ import 'package:sanmill/shared/common/constants.dart'; import 'package:sanmill/shared/theme/colors.dart'; class AppTheme { - AppTheme._(); + const AppTheme._(); + // TODO: restructure theming. Some theme Elements should be accessed via Theme.of(context) // Theme data static final lightThemeData = ThemeData( @@ -121,7 +122,7 @@ class AppTheme { color: moveHistoryTextColor, ); - static double boardTop = isLargeScreen() ? 75.0 : 36.0; + static double boardTop = isLargeScreen ? 75.0 : 36.0; static double boardMargin = 10.0; static double boardScreenPaddingH = 10.0; static double boardBorderRadius = 5.0; diff --git a/src/ui/flutter_app/pubspec.yaml b/src/ui/flutter_app/pubspec.yaml index 0e1ded96..ec34c62d 100644 --- a/src/ui/flutter_app/pubspec.yaml +++ b/src/ui/flutter_app/pubspec.yaml @@ -39,7 +39,7 @@ dev_dependencies: flutter_oss_licenses: ^1.0.1 flutter_test: sdk: flutter - lint: ^1.0.0 + lint: ^1.7.2 msix: ^2.1.3 flutter: