From 9c2a9cb0ad1a72222bb3fabf656a6e0dd153aee4 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Thu, 27 Jul 2023 23:17:04 +0800 Subject: [PATCH] Refactor: extract widget --- app/lib/widget/settings.dart | 105 +++++++++++++++++------------------ 1 file changed, 50 insertions(+), 55 deletions(-) diff --git a/app/lib/widget/settings.dart b/app/lib/widget/settings.dart index 38a79ca9..04e7d595 100644 --- a/app/lib/widget/settings.dart +++ b/app/lib/widget/settings.dart @@ -112,73 +112,63 @@ class _SettingsState extends State { }, ), ), - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.palette_outlined), label: L10n.global().settingsThemeTitle, description: L10n.global().settingsThemeDescription, - builder: () => const ThemeSettings(), + pageBuilder: () => const ThemeSettings(), ), - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.local_offer_outlined), label: L10n.global().settingsMetadataTitle, - builder: () => const MetadataSettings(), + pageBuilder: () => const MetadataSettings(), ), - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.image_outlined), label: L10n.global().photosTabLabel, description: L10n.global().settingsPhotosDescription, - builder: () => _PhotosSettings(account: widget.account), + pageBuilder: () => _PhotosSettings(account: widget.account), ), - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.grid_view_outlined), label: L10n.global().collectionsTooltip, - builder: () => _AlbumSettings(), + pageBuilder: () => _AlbumSettings(), ), - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.view_carousel_outlined), label: L10n.global().settingsViewerTitle, description: L10n.global().settingsViewerDescription, - builder: () => _ViewerSettings(), + pageBuilder: () => _ViewerSettings(), ), if (features.isSupportEnhancement) - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.auto_fix_high_outlined), label: L10n.global().settingsImageEditTitle, description: L10n.global().settingsImageEditDescription, - builder: () => const EnhancementSettings(), + pageBuilder: () => const EnhancementSettings(), ), - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.emoji_symbols_outlined), label: L10n.global().settingsMiscellaneousTitle, - builder: () => const _MiscSettings(), + pageBuilder: () => const _MiscSettings(), ), // if (_enabledExperiments.isNotEmpty) - // _buildSubSettings( - // context, + // _SubPageItem( // leading: const Icon(Icons.science_outlined), // label: L10n.global().settingsExperimentalTitle, // description: L10n.global().settingsExperimentalDescription, - // builder: () => _ExperimentalSettings(), + // pageBuilder: () => _ExperimentalSettings(), // ), - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.warning_amber), label: L10n.global().settingsExpertTitle, - builder: () => const ExpertSettings(), + pageBuilder: () => const ExpertSettings(), ), if (_isShowDevSettings) - _buildSubSettings( - context, + _SubPageItem( leading: const Icon(Icons.code_outlined), label: "Developer options", - builder: () => const DeveloperSettings(), + pageBuilder: () => const DeveloperSettings(), ), SettingsListCaption( label: L10n.global().settingsAboutSectionTitle, @@ -235,31 +225,6 @@ class _SettingsState extends State { ); } - Widget _buildSubSettings( - BuildContext context, { - Widget? leading, - required String label, - String? description, - required Widget Function() builder, - }) { - return ListTile( - leading: leading == null - ? null - : ListTileCenterLeading( - child: leading, - ), - title: Text(label), - subtitle: description == null ? null : Text(description), - onTap: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => builder(), - ), - ); - }, - ); - } - Future _onCaptureLogChanged(BuildContext context, bool value) async { if (value) { final result = await showDialog( @@ -319,6 +284,36 @@ class _SettingsState extends State { static const String _translationUrl = "https://bit.ly/3NwmdSw"; } +class _SubPageItem extends StatelessWidget { + const _SubPageItem({ + this.leading, + required this.label, + this.description, + required this.pageBuilder, + }); + + @override + Widget build(BuildContext context) { + return ListTile( + leading: leading == null ? null : ListTileCenterLeading(child: leading!), + title: Text(label), + subtitle: description == null ? null : Text(description!), + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => pageBuilder(), + ), + ); + }, + ); + } + + final Widget? leading; + final String label; + final String? description; + final Widget Function() pageBuilder; +} + class _PhotosSettings extends StatefulWidget { const _PhotosSettings({ Key? key,