From 4bf96f2df5e7d09b7c7b9a9d468fa669929782be Mon Sep 17 00:00:00 2001 From: shilangyu Date: Wed, 30 Aug 2023 10:55:24 +0200 Subject: [PATCH] Update readme --- packages/bloc_presentation/README.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/bloc_presentation/README.md b/packages/bloc_presentation/README.md index e7ff702..e7be3d0 100644 --- a/packages/bloc_presentation/README.md +++ b/packages/bloc_presentation/README.md @@ -17,7 +17,9 @@ flutter pub add bloc_presentation First, create an event which will be emitted: ```dart -class FailedToUpvote implements BlocPresentationEvent { +sealed class CommentCubitEvent {} + +class FailedToUpvote implements CommentCubitEvent { const FailedToUpvote(this.reason); final String reason; @@ -28,7 +30,7 @@ Next, extend your Bloc/Cubit with the presentation mixin which will give you access to the `emitPresentation` method: ```dart -class CommentCubit extends Cubit with BlocPresentationMixin { +class CommentCubit extends Cubit with BlocPresentationMixin { // body } ``` @@ -55,12 +57,13 @@ new states. Then, in the UI code one can react to such events using `BlocPresentationListener` or `useBlocPresentationListener`: ```dart -BlocPresentationListener( +BlocPresentationListener( listener: (context, event) { - if (event is FailedToUpvote) { - ScaffoldMessenger.of(context) - ..hideCurrentSnackBar() - ..showSnackBar(SnackBar(content: Text(event.reason))); + switch (event) { + case FailedToUpvote(): + ScaffoldMessenger.of(context) + ..hideCurrentSnackBar() + ..showSnackBar(SnackBar(content: Text(event.reason))); } }, child: MyWidget(),