Compare commits

..

2 Commits

@ -0,0 +1,3 @@
{
"cmake.ignoreCMakeListsMissing": true
}

@ -17,7 +17,7 @@ class SettingsController with ChangeNotifier {
_themeMode = await _settingsService.themeMode();
_hostname = await _settingsService.keyStr("hostname");
_username = await _settingsService.keyStr("username");
_password = await _settingsService.keyStrSec("password");
_password = await _settingsService.keyStr("password");
// Important! Inform listeners a change has occurred.
notifyListeners();
}
@ -35,10 +35,6 @@ class SettingsController with ChangeNotifier {
notifyListeners();
await _settingsService.setKeyStr(key, value);
}
Future<void> _setKeySec(String key, String value) async {
notifyListeners();
await _settingsService.setKeyStrSec(key, value);
}
Future<void> setHostname(String newHostname) async {
_hostname = newHostname;
@ -52,16 +48,24 @@ class SettingsController with ChangeNotifier {
}
Future<void> setPassword(String newPassword) async {
_password = newPassword;
await _setKeySec("password", password);
await _setKey("password", password);
Log().debug("password update");
}
/// Update and persist the ThemeMode based on the user's selection.
Future<void> updateThemeMode(ThemeMode? newThemeMode) async {
if (newThemeMode == null) return;
// Do not perform any work if new and old ThemeMode are identical
if (newThemeMode == _themeMode) return;
// Otherwise, store the new ThemeMode in memory
_themeMode = newThemeMode;
// Important! Inform listeners a change has occurred.
notifyListeners();
// Persist the changes to a local database or the internet using the
// SettingService.
await _settingsService.updateThemeMode(newThemeMode);
}
}

@ -1,8 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
/// A service that stores and retrieves user settings.
///
@ -10,18 +7,6 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
/// persist the user settings locally, use the shared_preferences package. If
/// you'd like to store settings on a web server, use the http package.
class SettingsService {
FlutterSecureStorage getSecureStorage() {
if (Platform.isAndroid) {
AndroidOptions getAndroidOptions() => const AndroidOptions(
encryptedSharedPreferences: true,
);
return FlutterSecureStorage(aOptions: getAndroidOptions());
} else {
return const FlutterSecureStorage();
}
}
/// Loads the User's preferred ThemeMode from local or remote storage.
Future<ThemeMode> themeMode() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
@ -47,16 +32,4 @@ class SettingsService {
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString(key, value);
}
Future<String> keyStrSec(String key) async {
const storage = FlutterSecureStorage();
String? res = await storage.read(key: key);
if (res == null) return "";
return res;
}
Future<void> setKeyStrSec(String key, String value) async {
const storage = FlutterSecureStorage();
await storage.write(key: key, value: value);
}
}

@ -22,8 +22,7 @@ class SettingsView extends StatelessWidget {
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
const Text("Config file is stored under \$HOME/.local/share"),
children: [
DropdownButton<ThemeMode>(
value: controller.themeMode,
onChanged: controller.updateThemeMode,

@ -6,10 +6,6 @@
#include "generated_plugin_registrant.h"
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
}

@ -3,7 +3,6 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

@ -18,7 +18,6 @@ dependencies:
shared_preferences:
async: ^2.11.0
logger: ^2.2.0
flutter_secure_storage: ^9.2.1
flutter_gen: any
dev_dependencies:

Loading…
Cancel
Save