Fix provider initialization error

This commit is contained in:
Ashita Prasad
2023-11-14 16:56:35 +05:30
parent 85f1cae768
commit 48056b71c1

View File

@ -30,9 +30,16 @@ final StateNotifierProvider<CollectionStateNotifier, Map<String, RequestModel>?>
class CollectionStateNotifier class CollectionStateNotifier
extends StateNotifier<Map<String, RequestModel>?> { extends StateNotifier<Map<String, RequestModel>?> {
CollectionStateNotifier(this.ref, this.hiveHandler) : super(null) { CollectionStateNotifier(this.ref, this.hiveHandler) : super(null) {
loadData(); var status = loadData();
Future.microtask(() => ref.read(activeIdStateProvider.notifier).state = Future.microtask(() {
ref.read(requestSequenceProvider)[0]); if (status) {
ref.read(requestSequenceProvider.notifier).state = [
state!.keys.first,
];
}
ref.read(activeIdStateProvider.notifier).state =
ref.read(requestSequenceProvider)[0];
});
} }
final Ref ref; final Ref ref;
@ -184,7 +191,7 @@ class CollectionStateNotifier
state = {}; state = {};
} }
void loadData() { bool loadData() {
var ids = hiveHandler.getIds(); var ids = hiveHandler.getIds();
if (ids == null || ids.length == 0) { if (ids == null || ids.length == 0) {
String newId = uuid.v1(); String newId = uuid.v1();
@ -193,7 +200,7 @@ class CollectionStateNotifier
id: newId, id: newId,
), ),
}; };
ref.read(requestSequenceProvider.notifier).state = [newId]; return true;
} else { } else {
Map<String, RequestModel> data = {}; Map<String, RequestModel> data = {};
for (var id in ids) { for (var id in ids) {
@ -205,6 +212,7 @@ class CollectionStateNotifier
} }
} }
state = data; state = data;
return false;
} }
} }