Skip to content

Commit

Permalink
refactor(settings): Separate SectionSwitchListTile
Browse files Browse the repository at this point in the history
  • Loading branch information
realth000 committed Aug 21, 2024
1 parent d697f11 commit 348a06c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
14 changes: 5 additions & 9 deletions lib/features/settings/view/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -179,11 +179,10 @@ class _SettingsPageState extends State<SettingsPage> {
),

/// 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<SettingsBloc>().add(
Expand Down Expand Up @@ -235,11 +234,10 @@ class _SettingsPageState extends State<SettingsPage> {
);
},
),
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
Expand Down Expand Up @@ -274,23 +272,21 @@ class _SettingsPageState extends State<SettingsPage> {
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
.read<SettingsBloc>()
.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<SettingsBloc>()
Expand Down
13 changes: 5 additions & 8 deletions lib/features/settings/view/thread_card_appearance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<SettingsBloc>().add(
SettingsValueChanged(
Expand All @@ -98,9 +98,8 @@ class _SettingsThreadCardAppearancePageState
),
),
),
SwitchListTile(
SectionSwitchListTile(
title: Text(tr.showLastReplyAuthor),
contentPadding: edgeInsetsL16R16,
value: settings.threadCardShowLastReplyAuthor,
onChanged: (v) => context.read<SettingsBloc>().add(
SettingsValueChanged(
Expand All @@ -109,9 +108,8 @@ class _SettingsThreadCardAppearancePageState
),
),
),
SwitchListTile(
SectionSwitchListTile(
title: Text(tr.highlightRecentThread),
contentPadding: edgeInsetsL16R16,
value: settings.threadCardHighlightRecentThread,
onChanged: (v) => context.read<SettingsBloc>().add(
SettingsValueChanged(
Expand All @@ -120,9 +118,8 @@ class _SettingsThreadCardAppearancePageState
),
),
),
SwitchListTile(
SectionSwitchListTile(
title: Text(tr.highlightAuthorName),
contentPadding: edgeInsetsL16R16,
value: settings.threadCardHighlightAuthorName,
onChanged: (v) => context.read<SettingsBloc>().add(
SettingsValueChanged(
Expand Down
46 changes: 46 additions & 0 deletions lib/widgets/section_switch_list_tile.dart
Original file line number Diff line number Diff line change
@@ -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,
});
}

0 comments on commit 348a06c

Please sign in to comment.