From b4974d8e20b9041a16d8cc6b62a8183548831e07 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Mon, 29 Mar 2021 00:42:52 +0800 Subject: [PATCH] flutter: Refactor about_page.dart --- .../flutter_app/lib/widgets/about_page.dart | 183 ++++++++++-------- 1 file changed, 99 insertions(+), 84 deletions(-) diff --git a/src/ui/flutter_app/lib/widgets/about_page.dart b/src/ui/flutter_app/lib/widgets/about_page.dart index 7b9888cf..1ceabd89 100644 --- a/src/ui/flutter_app/lib/widgets/about_page.dart +++ b/src/ui/flutter_app/lib/widgets/about_page.dart @@ -24,6 +24,7 @@ import 'package:package_info/package_info.dart'; import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/style/app_theme.dart'; import 'package:sanmill/style/colors.dart'; +import 'package:sanmill/widgets/settings_list_tile.dart'; import 'package:url_launcher/url_launcher.dart'; import 'license_page.dart'; @@ -67,76 +68,79 @@ class _AboutPageState extends State { body: SingleChildScrollView( padding: const EdgeInsets.all(16), child: Column( - children: [ - ListTile( - title: Text(S.of(context).versionInfo, - style: AppTheme.switchListTileTitleStyle), - subtitle: Text("Sanmill " + "$_version" + " " + mode, - style: TextStyle(color: UIColors.secondaryColor)), - onTap: _showVersionInfo, - ), - ListItemDivider(), - /* - ListTile( - title: - Text(S.of(context).viewInGooglePlayStore, style: AppTheme.switchListTileTitleStyle), - onTap: () => _launchURL( - 'https://play.google.com/store/apps/details?id=com.calcitem.sanmill'), - ), - ListItemDivider(), - */ - ListTile( - title: Text(S.of(context).feedback, - style: AppTheme.switchListTileTitleStyle), - onTap: () => - _launchURL('https://github.com/calcitem/Sanmill/issues'), - ), - ListItemDivider(), - ListTile( - title: Text(S.of(context).license, - style: AppTheme.switchListTileTitleStyle), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => LicenseAgreementPage(), - ), - ); - }), - ListItemDivider(), - ListTile( - title: Text(S.of(context).sourceCode, - style: AppTheme.switchListTileTitleStyle), - onTap: () => _launchURL('https://github.com/calcitem/Sanmill'), - ), - ListItemDivider(), - ListTile( - title: Text(S.of(context).privacyPolicy, - style: AppTheme.switchListTileTitleStyle), - onTap: () => _launchURL( - 'https://github.com/calcitem/Sanmill/wiki/privacy_policy'), - ), - ListItemDivider(), - ListTile( - title: Text(S.of(context).thirdPartyNotices, - style: AppTheme.switchListTileTitleStyle), - onTap: () => _launchURL( - 'https://github.com/calcitem/Sanmill/wiki/third-party_notices'), - ), - ListItemDivider(), - ListTile( - title: Text(S.of(context).thanks, - style: AppTheme.switchListTileTitleStyle), - onTap: () => - _launchURL('https://github.com/calcitem/Sanmill/wiki/thanks'), - ), - ListItemDivider(), - ], + children: children(context, mode), ), ), ); } + List children(BuildContext context, String mode) { + return [ + SettingsListTile( + context: context, + titleString: S.of(context).versionInfo, + subtitleString: "Sanmill " + "$_version" + " " + mode, + onTap: _showVersionInfo, + ), + ListItemDivider(), + /* + ListTile( + title: Text(S.of(context).viewInGooglePlayStore, + style: AppTheme.switchListTileTitleStyle), + onTap: () => _launchURL( + 'https://play.google.com/store/apps/details?id=com.calcitem.sanmill'), + ), + ListItemDivider(), + */ + SettingsListTile( + context: context, + titleString: S.of(context).feedback, + onTap: () => _launchURL('https://github.com/calcitem/Sanmill/issues'), + ), + ListItemDivider(), + SettingsListTile( + context: context, + titleString: S.of(context).license, + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LicenseAgreementPage(), + ), + ); + }, + ), + ListItemDivider(), + SettingsListTile( + context: context, + titleString: S.of(context).sourceCode, + onTap: () => _launchURL('https://github.com/calcitem/Sanmill'), + ), + ListItemDivider(), + SettingsListTile( + context: context, + titleString: S.of(context).privacyPolicy, + onTap: () => _launchURL( + 'https://github.com/calcitem/Sanmill/wiki/privacy_policy'), + ), + ListItemDivider(), + SettingsListTile( + context: context, + titleString: S.of(context).thirdPartyNotices, + onTap: () => _launchURL( + 'https://github.com/calcitem/Sanmill/wiki/third-party_notices'), + ), + ListItemDivider(), + SettingsListTile( + context: context, + titleString: S.of(context).thanks, + onTap: () => + _launchURL('https://github.com/calcitem/Sanmill/wiki/thanks'), + ), + ListItemDivider(), + ]; + } + _loadVersionInfo() async { if (Platform.isWindows) { setState(() { @@ -158,27 +162,38 @@ class _AboutPageState extends State { showDialog( context: context, barrierDismissible: false, - builder: (context) => AlertDialog( - title: Text(S.of(context).appName, - style: TextStyle(color: UIColors.primaryColor)), - content: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(S.of(context).version + ": $_version", - style: TextStyle(fontFamily: '')), - AppTheme.sizedBox, - AppTheme.sizedBox, - Text(S.of(context).copyright, - style: TextStyle(fontFamily: '', fontSize: 12)), - ], - ), - actions: [ - TextButton( - child: Text(S.of(context).ok), - onPressed: () => Navigator.of(context).pop()), + builder: (context) => alertDialog(context), + ); + } + + AlertDialog alertDialog(BuildContext context) { + return AlertDialog( + title: Text( + S.of(context).appName, + style: TextStyle(color: UIColors.primaryColor), + ), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + S.of(context).version + ": $_version", + style: TextStyle(fontFamily: ''), + ), + AppTheme.sizedBox, + AppTheme.sizedBox, + Text( + S.of(context).copyright, + style: TextStyle(fontFamily: '', fontSize: 12), + ), ], ), + actions: [ + TextButton( + child: Text(S.of(context).ok), + onPressed: () => Navigator.of(context).pop(), + ), + ], ); } }