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

39 lines
988 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?> {
_StateProvider(OathState? oathState) : 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>?> {
_CredentialsProvider(List<OathPair>? credentials) : 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
}
}
}