Settings: Use SwitchListTile instead of our custom widget

I didn't know this widget existed.
This commit is contained in:
Vishesh Handa
2019-11-02 10:50:20 +01:00
parent 1ebf9fc358
commit bb564f1511
2 changed files with 12 additions and 36 deletions

View File

@ -115,10 +115,10 @@ class SettingsListState extends State<SettingsList> {
return ListView(children: [
SettingsHeader('Display Settings'),
BoolPreference(
title: "Dark Theme",
defaultValue: brightness == Brightness.dark,
onChange: (bool newVal) {
SwitchListTile(
title: const Text("Dark Theme"),
value: brightness == Brightness.dark,
onChanged: (bool newVal) {
var b = newVal ? Brightness.dark : Brightness.light;
var dynamicTheme = DynamicTheme.of(context);
dynamicTheme.setBrightness(b);
@ -159,19 +159,19 @@ class SettingsListState extends State<SettingsList> {
),
const SizedBox(height: 16.0),
SettingsHeader("Analytics"),
BoolPreference(
title: "Collect Anonymous Usage Statistics",
defaultValue: Settings.instance.collectUsageStatistics,
onChange: (bool val) {
SwitchListTile(
title: const Text("Collect Anonymous Usage Statistics"),
value: Settings.instance.collectUsageStatistics,
onChanged: (bool val) {
Settings.instance.collectUsageStatistics = val;
Settings.instance.save();
setState(() {});
},
),
BoolPreference(
title: "Collect Anonymous Crash Reports",
defaultValue: Settings.instance.collectUsageStatistics,
onChange: (bool val) {
SwitchListTile(
title: const Text("Collect Anonymous Crash Reports"),
value: Settings.instance.collectCrashReports,
onChanged: (bool val) {
Settings.instance.collectCrashReports = val;
Settings.instance.save();
setState(() {});

View File

@ -63,27 +63,3 @@ class ListPreference extends StatelessWidget {
);
}
}
class BoolPreference extends StatelessWidget {
final String title;
final bool defaultValue;
final Function(bool) onChange;
BoolPreference({
@required this.title,
@required this.defaultValue,
@required this.onChange,
});
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(title),
trailing: Switch(
value: defaultValue,
onChanged: onChange,
),
onTap: () => onChange(!defaultValue),
);
}
}