Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
shilangyu committed Aug 30, 2023
1 parent 6c0fd07 commit 4bf96f2
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/bloc_presentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CommentState> with BlocPresentationMixin {
class CommentCubit extends Cubit<CommentState> with BlocPresentationMixin<CommentState, CommentCubitEvent> {
// body
}
```
Expand All @@ -55,12 +57,13 @@ new states. Then, in the UI code one can react to such events using
`BlocPresentationListener` or `useBlocPresentationListener`:

```dart
BlocPresentationListener<CommentCubit>(
BlocPresentationListener<CommentCubit, CommentCubitEvent>(
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(),
Expand Down

0 comments on commit 4bf96f2

Please sign in to comment.