From 72906ceb3b9059b73a16f2b434b34788d39e58c1 Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 28 Mar 2023 10:37:12 +0700 Subject: [PATCH] TF-1631 Add abstract class `FcmBaseController` (cherry picked from commit 920093f24785669fe5267dca95de8754a26096f3) --- .../controller/fcm_base_controller.dart | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/features/push_notification/presentation/controller/fcm_base_controller.dart diff --git a/lib/features/push_notification/presentation/controller/fcm_base_controller.dart b/lib/features/push_notification/presentation/controller/fcm_base_controller.dart new file mode 100644 index 000000000..f3c9358a2 --- /dev/null +++ b/lib/features/push_notification/presentation/controller/fcm_base_controller.dart @@ -0,0 +1,25 @@ + +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; +import 'package:core/utils/app_logger.dart'; +import 'package:dartz/dartz.dart'; + +abstract class FcmBaseController { + + void consumeState(Stream> newStateStream) { + newStateStream.listen( + _handleStateStream, + onError: (error, stackTrace) { + logError('FcmBaseController::consumeState():onError:error: $error | stackTrace: $stackTrace'); + } + ); + } + + void _handleStateStream(Either newState) { + newState.fold(handleFailureViewState, handleSuccessViewState); + } + + void handleFailureViewState(Failure failure); + + void handleSuccessViewState(Success success); +} \ No newline at end of file