-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[344] feat: move tiles settings to new page
- Loading branch information
1 parent
081b7bd
commit 333cb7a
Showing
4 changed files
with
192 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
lib/pages/settings/pages/settings_notes_tiles_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:material_symbols_icons/material_symbols_icons.dart'; | ||
import 'package:settings_tiles/settings_tiles.dart'; | ||
|
||
import '../../../common/constants/constants.dart'; | ||
import '../../../common/constants/paddings.dart'; | ||
import '../../../common/navigation/app_bars/basic_app_bar.dart'; | ||
import '../../../common/navigation/top_navigation.dart'; | ||
import '../../../common/preferences/preference_key.dart'; | ||
import '../../../common/preferences/watched_preferences.dart'; | ||
import '../../../providers/preferences/preferences_provider.dart'; | ||
import '../../../utils/keys.dart'; | ||
|
||
/// Settings related to the appearance of the application. | ||
class SettingsNotesTilesPage extends ConsumerStatefulWidget { | ||
/// Default constructor. | ||
const SettingsNotesTilesPage({super.key}); | ||
|
||
@override | ||
ConsumerState<SettingsNotesTilesPage> createState() => _SettingsNotesTilesPageState(); | ||
} | ||
|
||
class _SettingsNotesTilesPageState extends ConsumerState<SettingsNotesTilesPage> { | ||
/// Toggles the setting to show background of the notes tiles. | ||
void _toggleShowTilesBackground(bool toggled) { | ||
PreferenceKey.showTilesBackground.set(toggled); | ||
|
||
ref.read(preferencesProvider.notifier).update(WatchedPreferences(showTilesBackground: toggled)); | ||
} | ||
|
||
/// Toggles the setting to show the separators between the notes tiles. | ||
void _toggleShowSeparators(bool toggled) { | ||
PreferenceKey.showSeparators.set(toggled); | ||
|
||
ref.read(preferencesProvider.notifier).update(WatchedPreferences(showSeparators: toggled)); | ||
} | ||
|
||
/// Toggles the setting to show background of the notes tiles. | ||
void _toggleShowTitlesOnly(bool toggled) { | ||
PreferenceKey.showTitlesOnly.set(toggled); | ||
|
||
ref.read(preferencesProvider.notifier).update(WatchedPreferences(showTitlesOnly: toggled)); | ||
} | ||
|
||
/// Toggles the setting to show background of the notes tiles. | ||
void _toggleShowTitlesOnlyDisableInSearchView(bool toggled) { | ||
setState(() { | ||
PreferenceKey.showTitlesOnlyDisableInSearchView.set(toggled); | ||
}); | ||
} | ||
|
||
/// Sets the note content preview maximum lines count to the new [noteContentPreviewMaxLines]. | ||
void _submittedNoteContentPreviewMaxLines(double noteContentPreviewMaxLines) { | ||
PreferenceKey.noteContentPreviewMaxLines.set(noteContentPreviewMaxLines.toInt()); | ||
|
||
ref.read(preferencesProvider.notifier).update( | ||
WatchedPreferences(noteContentPreviewMaxLines: noteContentPreviewMaxLines.toInt()), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final showTilesBackground = ref.watch(preferencesProvider.select((preferences) => preferences.showTilesBackground)); | ||
final showSeparators = ref.watch(preferencesProvider.select((preferences) => preferences.showSeparators)); | ||
final showTitlesOnly = ref.watch(preferencesProvider.select((preferences) => preferences.showTitlesOnly)); | ||
final showTitlesOnlyDisableInSearchView = PreferenceKey.showTitlesOnlyDisableInSearchView.getPreferenceOrDefault(); | ||
final noteContentPreviewMaxLines = | ||
ref.watch(preferencesProvider.select((preferences) => preferences.noteContentPreviewMaxLines)); | ||
|
||
return Scaffold( | ||
appBar: TopNavigation( | ||
key: Keys.appBarSettingsMainSubpage, | ||
appbar: BasicAppBar( | ||
title: l.navigation_settings_notes_tiles, | ||
//back: true, | ||
), | ||
), | ||
body: SingleChildScrollView( | ||
child: Padding( | ||
padding: Paddings.bottomSystemUi, | ||
child: Column( | ||
children: [ | ||
SettingSection( | ||
divider: null, | ||
title: l.settings_page_notes_tiles_appearance_section, | ||
tiles: [ | ||
SettingSwitchTile( | ||
icon: Icons.gradient, | ||
title: l.settings_show_tiles_background, | ||
description: l.settings_show_tiles_background_description, | ||
toggled: showTilesBackground, | ||
onChanged: _toggleShowTilesBackground, | ||
), | ||
SettingSwitchTile( | ||
icon: Icons.safety_divider, | ||
title: l.settings_show_separators, | ||
description: l.settings_show_separators_description, | ||
toggled: showSeparators, | ||
onChanged: _toggleShowSeparators, | ||
), | ||
], | ||
), | ||
SettingSection( | ||
divider: null, | ||
title: l.settings_page_notes_tiles_content_section, | ||
tiles: [ | ||
SettingSwitchTile( | ||
icon: Icons.title, | ||
title: l.settings_show_titles_only, | ||
description: l.settings_show_titles_only_description, | ||
toggled: showTitlesOnly, | ||
onChanged: _toggleShowTitlesOnly, | ||
), | ||
SettingSwitchTile( | ||
enabled: showTitlesOnly, | ||
icon: Symbols.feature_search, | ||
title: l.settings_show_titles_only_disable_in_search_view, | ||
description: l.settings_show_titles_only_disable_in_search_view_description, | ||
toggled: showTitlesOnlyDisableInSearchView, | ||
onChanged: _toggleShowTitlesOnlyDisableInSearchView, | ||
), | ||
SettingSliderTile( | ||
icon: Icons.short_text, | ||
title: l.settings_content_preview_max_lines, | ||
description: l.settings_content_preview_max_lines_description, | ||
value: '$noteContentPreviewMaxLines', | ||
dialogTitle: l.settings_content_preview_max_lines, | ||
label: (noteContentPreviewMaxLines) => '${noteContentPreviewMaxLines.toInt()}', | ||
min: 1.0, | ||
max: 10.0, | ||
divisions: 9, | ||
initialValue: noteContentPreviewMaxLines.toDouble(), | ||
onSubmitted: _submittedNoteContentPreviewMaxLines, | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters