-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch settings to riverpod (maybe change to one obj later)
- Loading branch information
1 parent
72df858
commit e99419d
Showing
6 changed files
with
90 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,50 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
import 'package:worklog_assistant/src/storage/prefs.dart'; | ||
|
||
class SettingsProvider with ChangeNotifier { | ||
String _jiraUrl = ""; | ||
String get jiraUrl => _jiraUrl; | ||
part 'settings_provider.g.dart'; | ||
|
||
SettingsProvider() { | ||
loadSettings(); | ||
} | ||
@riverpod | ||
class JiraUrl extends _$JiraUrl { | ||
@override | ||
String? build() { | ||
final prefs = ref.watch(prefsProvider).requireValue; | ||
|
||
Future loadSettings() async { | ||
SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
// Load the saved theme mode setting from shared preferences. | ||
final jiraUrl = prefs.getString('jiraUrl'); | ||
|
||
_jiraUrl = prefs.getString("jiraUrl") ?? ""; | ||
_jiraPat = prefs.getString("jiraPat") ?? ""; | ||
notifyListeners(); | ||
// Return [ThemeMode] based on the saved setting, or [ThemeMode.system] | ||
// if there's no saved setting yet. | ||
return jiraUrl; | ||
} | ||
|
||
updateJiraUrl(String url) async { | ||
_jiraUrl = url; | ||
SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
void set(String jiraUrl) { | ||
final prefs = ref.read(prefsProvider).requireValue; | ||
|
||
prefs.setString("jiraUrl", url); | ||
prefs.setString('jiraUrl', jiraUrl); | ||
|
||
notifyListeners(); | ||
ref.invalidateSelf(); | ||
} | ||
} | ||
|
||
@riverpod | ||
class JiraPat extends _$JiraPat { | ||
@override | ||
String? build() { | ||
final prefs = ref.watch(prefsProvider).requireValue; | ||
|
||
String _jiraPat = ""; | ||
String get jiraPat => _jiraPat; | ||
// Load the saved theme mode setting from shared preferences. | ||
final jiraPat = prefs.getString('jiraPat'); | ||
|
||
updateJiraPat(String pat) async { | ||
_jiraPat = pat; | ||
SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
// Return [ThemeMode] based on the saved setting, or [ThemeMode.system] | ||
// if there's no saved setting yet. | ||
return jiraPat; | ||
} | ||
|
||
void set(String jiraPat) { | ||
final prefs = ref.read(prefsProvider).requireValue; | ||
|
||
prefs.setString("jiraPat", pat); | ||
prefs.setString('jiraPat', jiraPat); | ||
|
||
notifyListeners(); | ||
ref.invalidateSelf(); | ||
} | ||
} | ||
|
||
final settingsProvider = ChangeNotifierProvider<SettingsProvider>((ref) { | ||
var s = SettingsProvider(); | ||
s.loadSettings(); | ||
return s; | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters