Cleaned up code, implemented message queue to notify subscribers of document updates.

This commit is contained in:
Anton Stubenbord
2023-02-06 01:04:13 +01:00
parent 337c178be8
commit 4d7fab1839
111 changed files with 1412 additions and 1029 deletions

View File

@@ -13,7 +13,13 @@ class DocumentSearchCubit extends HydratedCubit<DocumentSearchState>
final DocumentChangedNotifier notifier;
DocumentSearchCubit(this.api, this.notifier)
: super(const DocumentSearchState());
: super(const DocumentSearchState()) {
notifier.subscribe(
this,
onDeleted: remove,
onUpdated: replace,
);
}
Future<void> search(String query) async {
emit(state.copyWith(
@@ -61,6 +67,12 @@ class DocumentSearchCubit extends HydratedCubit<DocumentSearchState>
));
}
@override
Future<void> close() {
notifier.unsubscribe(this);
return super.close();
}
@override
DocumentSearchState? fromJson(Map<String, dynamic> json) {
return DocumentSearchState.fromJson(json);

View File

@@ -158,18 +158,16 @@ class _DocumentSearchPageState extends State<DocumentSearchPage> {
isLabelClickable: false,
isLoading: state.isLoading,
hasLoaded: state.hasLoaded,
onTap: (document) async {
final updatedDocument = await Navigator.pushNamed(
enableHeroAnimation: false,
onTap: (document) {
Navigator.pushNamed(
context,
DocumentDetailsRoute.routeName,
arguments: DocumentDetailsRouteArguments(
document: document,
isLabelClickable: false,
),
) as DocumentModel?;
if (updatedDocument != document) {
context.read<DocumentSearchCubit>().reload();
}
);
},
)
],