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
|
|
|
|
2022-03-04 19:07:12 +03:00
|
|
|
void setFromString(String input) {
|
2022-03-03 18:43:36 +03:00
|
|
|
var resultJson = jsonDecode(input);
|
2022-05-05 14:56:08 +03:00
|
|
|
state = OathState.fromJson(resultJson);
|
2022-03-03 18:43:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 19:24:26 +03:00
|
|
|
final androidCredentialsProvider =
|
2022-04-07 17:41:57 +03:00
|
|
|
StateNotifierProvider<_CredentialsProvider, List<OathPair>?>((ref) {
|
|
|
|
return _CredentialsProvider(null);
|
2022-03-03 18:43:36 +03:00
|
|
|
});
|
|
|
|
|
2022-04-07 17:41:57 +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
|
|
|
|
2022-03-04 19:07:12 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|