feat: persist MQTT broker settings in store

This commit is contained in:
2026-05-13 11:59:23 +02:00
parent 60044b9ce0
commit 7bf3aa29ea
2 changed files with 26 additions and 0 deletions
@@ -9,6 +9,8 @@ class CredentialStore {
static const _passwordKey = 'localiserd_password';
static const _hostKey = 'localiserd_host';
static const _portKey = 'localiserd_port';
static const _mqttHostKey = 'mqtt_host';
static const _mqttPortKey = 'mqtt_port';
final _storage = const FlutterSecureStorage();
@@ -46,6 +48,24 @@ class CredentialStore {
return ServerConfig(host: host, port: port);
}
Future<void> saveMqttBroker(String host, int port) => Future.wait([
_storage.write(key: _mqttHostKey, value: host),
_storage.write(key: _mqttPortKey, value: port.toString()),
]).then((_) {});
Future<({String host, int port})?> loadMqttBroker() async {
final results = await Future.wait([
_storage.read(key: _mqttHostKey),
_storage.read(key: _mqttPortKey),
]);
final host = results[0];
final portStr = results[1];
if (host == null || portStr == null) return null;
final port = int.tryParse(portStr);
if (port == null) return null;
return (host: host, port: port);
}
Future<void> clear() => Future.wait([
_storage.delete(key: _usernameKey),
_storage.delete(key: _passwordKey),
+6
View File
@@ -44,6 +44,12 @@ final credentialStoreProvider = Provider<CredentialStore>((ref) {
return CredentialStore();
});
/// MQTT broker settings stored locally on the device.
/// Null if not yet configured. Set via [CredentialStore.saveMqttBroker].
final mqttBrokerProvider = FutureProvider<({String host, int port})?>(
(ref) => ref.watch(credentialStoreProvider).loadMqttBroker(),
);
// ---------------------------------------------------------------------------
// Feature clients — throw if required state is missing
// ---------------------------------------------------------------------------