Add settings page #46
2 changed files with 61 additions and 19 deletions
WIP settings search
commit
1ea5899791
|
|
@ -3,11 +3,14 @@ import "package:flutter/material.dart";
|
|||
class Setting {
|
||||
final String title;
|
||||
final String description;
|
||||
final Widget Function(String title, String description) builder;
|
||||
final IconData icon;
|
||||
final Widget Function(String title, String description, IconData icon)
|
||||
builder;
|
||||
|
||||
Setting({
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.builder,
|
||||
required this.icon,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,13 +37,16 @@ class SettingsPage extends ConsumerWidget {
|
|||
title: "Theme",
|
||||
description:
|
||||
"Toggle between Light Mode, Dark Mode, and System themes.",
|
||||
builder: (title, description) => DialogListTile<ThemeMode>(
|
||||
icon: Icon(Icons.contrast),
|
||||
icon: Icons.contrast,
|
||||
builder: (title, description, icon) =>
|
||||
DialogListTile<ThemeMode>(
|
||||
icon: Icon(icon),
|
||||
title: title,
|
||||
subtitle: Text(description),
|
||||
initialValue: settings.theme,
|
||||
options: ThemeMode.values,
|
||||
getName: (option) => toBeginningOfSentenceCase(option.name),
|
||||
getName: (option) =>
|
||||
toBeginningOfSentenceCase(option.name),
|
||||
onChanged: (value) => ref
|
||||
.watch(SettingsController.provider.notifier)
|
||||
.set(settings.copyWith(theme: value))
|
||||
|
|
@ -52,12 +55,13 @@ class SettingsPage extends ConsumerWidget {
|
|||
),
|
||||
Setting(
|
||||
title: "Use Dynamic Theme",
|
||||
icon: Icons.palette,
|
||||
description:
|
||||
"Toggle on or off Dynamic Theme. Only available on Android, Linux, Windows, or MacOS.",
|
||||
builder: (title, description) => SwitchListTile(
|
||||
builder: (title, description, icon) => SwitchListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(description),
|
||||
secondary: Icon(Icons.palette),
|
||||
secondary: Icon(icon),
|
||||
value: settings.useDynamicTheming,
|
||||
onChanged:
|
||||
(Platform.isAndroid ||
|
||||
|
|
@ -73,12 +77,13 @@ class SettingsPage extends ConsumerWidget {
|
|||
),
|
||||
Setting(
|
||||
title: "Use System Font",
|
||||
icon: Icons.abc,
|
||||
description:
|
||||
"Use the system's sans and emoji fonts, instead of Flutter's bundled fonts. Turn this off if you are having issues rendering emoji.",
|
||||
builder: (title, description) => SwitchListTile(
|
||||
builder: (title, description, icon) => SwitchListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(description),
|
||||
secondary: Icon(Icons.abc),
|
||||
secondary: Icon(icon),
|
||||
value: settings.useSystemFont,
|
||||
onChanged: (value) => ref
|
||||
.watch(SettingsController.provider.notifier)
|
||||
|
|
@ -98,8 +103,40 @@ class SettingsPage extends ConsumerWidget {
|
|||
final searchBar = SearchAnchor.bar(
|
||||
barHintText: "Search...",
|
||||
suggestionsBuilder: (context, controller) {
|
||||
// TODO
|
||||
return [];
|
||||
final categories = buildCategories(Settings());
|
||||
final query = controller.text.toLowerCase();
|
||||
|
||||
final matches = categories.values
|
||||
.expand((categoryList) => categoryList.asMap().entries)
|
||||
.expand(
|
||||
(categoryEntry) => categoryEntry.value.settings
|
||||
.asMap()
|
||||
.entries
|
||||
.where(
|
||||
(settingEntry) =>
|
||||
settingEntry.value.title.toLowerCase().contains(
|
||||
query,
|
||||
) ||
|
||||
settingEntry.value.description
|
||||
.toLowerCase()
|
||||
.contains(query),
|
||||
)
|
||||
.map(
|
||||
(settingEntry) => (
|
||||
(categoryEntry.key, settingEntry.key),
|
||||
settingEntry.value,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toIList();
|
||||
|
||||
return matches.map(
|
||||
(match) => ListTile(
|
||||
leading: Icon(match.$2.icon),
|
||||
title: Text(match.$2.title),
|
||||
subtitle: Text(match.$2.description),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -164,6 +201,7 @@ class SettingsPage extends ConsumerWidget {
|
|||
child: setting.builder(
|
||||
setting.title,
|
||||
setting.description,
|
||||
setting.icon,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -223,6 +261,7 @@ class SettingsPage extends ConsumerWidget {
|
|||
child: setting.builder(
|
||||
setting.title,
|
||||
setting.description,
|
||||
setting.icon,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue