Files
GitJournal/lib/analytics/config.dart
Vishesh Handa 657721adc6 Update dart-git and stop using the Result class
Instead we're going to move back to standard exceptions.

Using a custom Result class has created far far more problems
- The Stacktraces aren't always right
- Sometimes one forgets to check the Result error
- All other exception throwing code needing to be converted to Results
- Non idiomatic Dart code

I think it's better to just go back to exceptions. They have their
problems, but overall, I think it's a better approach.
2023-11-24 14:03:30 +01:00

36 lines
878 B
Dart

/*
* SPDX-FileCopyrightText: 2019-2021 Vishesh Handa <me@vhanda.in>
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import 'package:flutter/foundation.dart';
import 'package:gitjournal/settings/settings_sharedpref.dart';
import 'package:shared_preferences/shared_preferences.dart';
class AnalyticsConfig extends ChangeNotifier with SettingsSharedPref {
AnalyticsConfig(this.id, this.pref);
@override
final String id;
@override
final SharedPreferences pref;
var appVersion = "";
var enabled = true;
void load(SharedPreferences pref) {
appVersion = pref.getString("appVersion") ?? "";
enabled = getBool("collectUsageStatistics") ?? enabled;
}
Future<void> save() async {
var def = AnalyticsConfig(id, pref);
await setBool("collectUsageStatistics", enabled, def.enabled);
await pref.setString("appVersion", appVersion);
}
}