mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-01 06:54:41 +08:00
Settings: Replace CheckboxPreference with BoolPreference
It's better to have our own small class for this as the one provided with the library tries to contact the PreferencesService and that isn't what we want.
This commit is contained in:
@ -166,30 +166,22 @@ class SettingsListState extends State<SettingsList> {
|
||||
),
|
||||
SizedBox(height: 16.0),
|
||||
SettingsHeader("Analytics"),
|
||||
CheckboxPreference(
|
||||
"Collect Anonymous Usage Statistics",
|
||||
"usage_stats",
|
||||
defaultVal: Settings.instance.collectUsageStatistics,
|
||||
onEnable: () {
|
||||
Settings.instance.collectUsageStatistics = true;
|
||||
Settings.instance.save();
|
||||
},
|
||||
onDisable: () {
|
||||
Settings.instance.collectUsageStatistics = false;
|
||||
BoolPreference(
|
||||
title: "Collect Anonymous Usage Statistics",
|
||||
defaultValue: Settings.instance.collectUsageStatistics,
|
||||
onChange: (bool val) {
|
||||
Settings.instance.collectUsageStatistics = val;
|
||||
Settings.instance.save();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
CheckboxPreference(
|
||||
"Collect Anonymous Crash Reports",
|
||||
"crash_reports",
|
||||
defaultVal: Settings.instance.collectCrashReports,
|
||||
onEnable: () {
|
||||
Settings.instance.collectCrashReports = true;
|
||||
Settings.instance.save();
|
||||
},
|
||||
onDisable: () {
|
||||
Settings.instance.collectCrashReports = false;
|
||||
BoolPreference(
|
||||
title: "Collect Anonymous Crash Reports",
|
||||
defaultValue: Settings.instance.collectUsageStatistics,
|
||||
onChange: (bool val) {
|
||||
Settings.instance.collectCrashReports = val;
|
||||
Settings.instance.save();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
VersionNumberTile(),
|
||||
@ -350,3 +342,27 @@ 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: Checkbox(
|
||||
value: defaultValue,
|
||||
onChanged: onChange,
|
||||
),
|
||||
onTap: () => onChange(!defaultValue),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user