I am using Firebase with Flutter. Getting firebase stream from repository. In the StateNotifier
class, using AsyncValue
union class for state management using 'loading', 'data', and 'error' states in my ConsumerWidget
.
My Code:
class MyTableNotifier extends StateNotifier<AsyncValue<TableModel>> {
final Ref ref;
MyTableNotifier(this.ref) : super(const AsyncValue.loading());
getMyTable(String tableId) async {
try {
final repo = ref.watch(tableRepoProvider);
state = const AsyncValue.loading();
var tbl = repo.getTable(tableId);
state = AsyncValue.data(tbl); <-- error (The argument type Stream<TableModel> cant be assigned to the parameter type 'TableModel'
print('i am hit');
} on FirebaseException catch (e) {
state = AsyncValue.error(e.message!);
}
}
}
Error: I am getting the Stream object from the repository, however I cant find a way to use AsyncVal with Stream type object.
What I have tried:
I have tried to change the AsyncValue> type of the statenotifier to Stream but this way I lose the loading, data and error states in the AsyncUnion class.
Help: Can please someone guide me in the right direction, where I still use the loading, data and error states with Stream objects?
Thanks