Settings: Change Theme dropDown to AlertBox

This follows the MaterialDesign guides and also looks way better
This commit is contained in:
Vishesh Handa
2019-10-08 14:22:38 +02:00
parent 70cc57f89c
commit e0e90f3819

View File

@ -110,14 +110,15 @@ class SettingsListState extends State<SettingsList> {
}, },
); );
var brightness = DynamicTheme.of(context).brightness;
return PreferencePage([ return PreferencePage([
SettingsHeader('Display Settings'), SettingsHeader('Display Settings'),
DropdownPreference( ListPreference(
'Theme', title: "Theme",
'theme', currentOption: brightness == Brightness.light ? "Light" : "Dark",
defaultVal: "Light", options: ["Light", "Dark"],
values: ["Light", "Dark"], onChange: (String newVal) {
onChange: (newVal) {
var dynamicTheme = DynamicTheme.of(context); var dynamicTheme = DynamicTheme.of(context);
switch (newVal) { switch (newVal) {
case "Dark": case "Dark":
@ -315,3 +316,53 @@ class FontSizeSettingsDialog extends StatelessWidget {
); );
} }
} }
class ListPreference extends StatelessWidget {
final String title;
final String currentOption;
final List<String> options;
Function onChange;
ListPreference({
@required this.title,
@required this.currentOption,
@required this.options,
@required this.onChange,
});
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(title),
subtitle: Text(currentOption),
onTap: () async {
var option = await showDialog<String>(
context: context,
builder: (BuildContext context) {
var children = <Widget>[];
for (var o in options) {
var tile = ListTile(
title: Text(o),
onTap: () {
Navigator.of(context).pop(o);
},
);
children.add(tile);
}
return AlertDialog(
title: Text(title),
content: SingleChildScrollView(
child: ListBody(
children: children,
),
),
);
});
if (option != null) {
onChange(option);
}
},
);
}
}