From 348a06c92d8f422c6e7460cf2c4128a577680f24 Mon Sep 17 00:00:00 2001 From: realth000 Date: Wed, 21 Aug 2024 23:58:37 +0800 Subject: [PATCH] refactor(settings): Separate SectionSwitchListTile --- lib/features/settings/view/settings_page.dart | 14 ++---- .../settings/view/thread_card_appearance.dart | 13 ++---- lib/widgets/section_switch_list_tile.dart | 46 +++++++++++++++++++ 3 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 lib/widgets/section_switch_list_tile.dart diff --git a/lib/features/settings/view/settings_page.dart b/lib/features/settings/view/settings_page.dart index 233c2154..8696141b 100644 --- a/lib/features/settings/view/settings_page.dart +++ b/lib/features/settings/view/settings_page.dart @@ -4,7 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:go_router/go_router.dart'; import 'package:tsdm_client/constants/constants.dart'; -import 'package:tsdm_client/constants/layout.dart'; import 'package:tsdm_client/features/settings/bloc/settings_bloc.dart'; import 'package:tsdm_client/features/settings/repositories/settings_repository.dart'; import 'package:tsdm_client/features/settings/widgets/check_in_dialog.dart'; @@ -20,6 +19,7 @@ import 'package:tsdm_client/shared/providers/checkin_provider/models/check_in_fe import 'package:tsdm_client/utils/platform.dart'; import 'package:tsdm_client/utils/show_bottom_sheet.dart'; import 'package:tsdm_client/widgets/section_list_tile.dart'; +import 'package:tsdm_client/widgets/section_switch_list_tile.dart'; import 'package:tsdm_client/widgets/section_title_text.dart'; /// Settings page of the app. @@ -179,11 +179,10 @@ class _SettingsPageState extends State { ), /// Shortcut in forum card. - SwitchListTile( + SectionSwitchListTile( secondary: const Icon(Icons.shortcut_outlined), title: Text(tr.showShortcutInForumCard.title), subtitle: Text(tr.showShortcutInForumCard.detail), - contentPadding: edgeInsetsL16R16, value: showForumCardShortcut, onChanged: (v) async { context.read().add( @@ -235,11 +234,10 @@ class _SettingsPageState extends State { ); }, ), - SwitchListTile( + SectionSwitchListTile( secondary: const Icon(Icons.notifications_outlined), title: Text(tr.showUnreadInfoHint.title), subtitle: Text(tr.showUnreadInfoHint.detail), - contentPadding: edgeInsetsL16R16, value: showUnreadInfoHint, onChanged: (v) async { context @@ -274,11 +272,10 @@ class _SettingsPageState extends State { return [ SectionTitleText(tr.title), if (isMobile) - SwitchListTile( + SectionSwitchListTile( secondary: const Icon(Icons.block_outlined), title: Text(tr.doublePressExit.title), subtitle: Text(tr.doublePressExit.detail), - contentPadding: edgeInsetsL16R16, value: doublePressExit, onChanged: (v) async { context @@ -286,11 +283,10 @@ class _SettingsPageState extends State { .add(SettingsValueChanged(SettingsKeys.doublePressExit, v)); }, ), - SwitchListTile( + SectionSwitchListTile( secondary: const Icon(Icons.align_vertical_top_outlined), title: Text(tr.threadReverseOrder.title), subtitle: Text(tr.threadReverseOrder.detail), - contentPadding: edgeInsetsL16R16, value: threadReverseOrder, onChanged: (v) async => context .read() diff --git a/lib/features/settings/view/thread_card_appearance.dart b/lib/features/settings/view/thread_card_appearance.dart index 1c328341..65ac276e 100644 --- a/lib/features/settings/view/thread_card_appearance.dart +++ b/lib/features/settings/view/thread_card_appearance.dart @@ -6,6 +6,7 @@ import 'package:tsdm_client/features/settings/bloc/settings_bloc.dart'; import 'package:tsdm_client/i18n/strings.g.dart'; import 'package:tsdm_client/shared/models/models.dart'; import 'package:tsdm_client/widgets/card/thread_card/thread_card.dart'; +import 'package:tsdm_client/widgets/section_switch_list_tile.dart'; /// Settings page for thread card appearance class SettingsThreadCardAppearancePage extends StatefulWidget { @@ -87,9 +88,8 @@ class _SettingsThreadCardAppearancePageState child: ListView( shrinkWrap: true, children: [ - SwitchListTile( + SectionSwitchListTile( title: Text(tr.infoRowAlignCenter), - contentPadding: edgeInsetsL16R16, value: settings.threadCardInfoRowAlignCenter, onChanged: (v) => context.read().add( SettingsValueChanged( @@ -98,9 +98,8 @@ class _SettingsThreadCardAppearancePageState ), ), ), - SwitchListTile( + SectionSwitchListTile( title: Text(tr.showLastReplyAuthor), - contentPadding: edgeInsetsL16R16, value: settings.threadCardShowLastReplyAuthor, onChanged: (v) => context.read().add( SettingsValueChanged( @@ -109,9 +108,8 @@ class _SettingsThreadCardAppearancePageState ), ), ), - SwitchListTile( + SectionSwitchListTile( title: Text(tr.highlightRecentThread), - contentPadding: edgeInsetsL16R16, value: settings.threadCardHighlightRecentThread, onChanged: (v) => context.read().add( SettingsValueChanged( @@ -120,9 +118,8 @@ class _SettingsThreadCardAppearancePageState ), ), ), - SwitchListTile( + SectionSwitchListTile( title: Text(tr.highlightAuthorName), - contentPadding: edgeInsetsL16R16, value: settings.threadCardHighlightAuthorName, onChanged: (v) => context.read().add( SettingsValueChanged( diff --git a/lib/widgets/section_switch_list_tile.dart b/lib/widgets/section_switch_list_tile.dart new file mode 100644 index 00000000..ce8da4bf --- /dev/null +++ b/lib/widgets/section_switch_list_tile.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; +import 'package:tsdm_client/constants/layout.dart'; + +/// [SwitchListTile] used in section. +class SectionSwitchListTile extends SwitchListTile { + /// Constructor. + const SectionSwitchListTile({ + required super.value, + required super.onChanged, + super.activeColor, + super.activeTrackColor, + super.inactiveThumbColor, + super.inactiveTrackColor, + super.activeThumbImage, + super.onActiveThumbImageError, + super.inactiveThumbImage, + super.onInactiveThumbImageError, + super.thumbColor, + super.trackColor, + super.trackOutlineColor, + super.thumbIcon, + super.materialTapTargetSize, + super.dragStartBehavior, + super.mouseCursor, + super.overlayColor, + super.splashRadius, + super.focusNode, + super.onFocusChange, + super.autofocus = false, + super.tileColor, + super.title, + super.subtitle, + super.isThreeLine = false, + super.dense, + super.contentPadding = edgeInsetsL16R16, + super.secondary, + super.selected = false, + super.controlAffinity = ListTileControlAffinity.platform, + super.shape, + super.selectedTileColor, + super.visualDensity, + super.enableFeedback, + super.hoverColor, + super.key, + }); +}