yubioath-flutter/lib/android/oath/command_providers.dart

39 lines
933 B
Dart
Raw Normal View History

2022-03-03 18:43:36 +03:00
import 'dart:convert';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../oath/models.dart';
2022-03-03 19:24:26 +03:00
final androidStateProvider =
StateNotifierProvider<_StateProvider, OathState?>((ref) {
return _StateProvider(null);
2022-03-03 18:43:36 +03:00
});
2022-03-03 19:24:26 +03:00
class _StateProvider extends StateNotifier<OathState?> {
2022-05-12 10:56:55 +03:00
_StateProvider(super.oathState);
2022-03-03 18:43:36 +03:00
void setFromString(String input) {
2022-03-03 18:43:36 +03:00
var resultJson = jsonDecode(input);
state = OathState.fromJson(resultJson);
2022-03-03 18:43:36 +03:00
}
}
2022-03-03 19:24:26 +03:00
final androidCredentialsProvider =
StateNotifierProvider<_CredentialsProvider, List<OathPair>?>((ref) {
return _CredentialsProvider(null);
2022-03-03 18:43:36 +03:00
});
class _CredentialsProvider extends StateNotifier<List<OathPair>?> {
2022-05-12 10:56:55 +03:00
_CredentialsProvider(super.credentials);
2022-03-03 18:43:36 +03:00
void setFromString(String input) {
2022-03-03 18:43:36 +03:00
var result = jsonDecode(input);
2022-05-06 15:27:33 +03:00
if (result is List) {
state = result.map((e) => OathPair.fromJson(e)).toList();
} else {
state = [];
2022-03-03 18:43:36 +03:00
}
}
}