Skip to content

Commit

Permalink
Merge pull request #7 from LanarsInc/release/1.0.2
Browse files Browse the repository at this point in the history
Release/1.0.2
  • Loading branch information
vizhan-lanars authored Sep 7, 2023
2 parents 9c74a8c + ef24be7 commit 1908992
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.2 - 07.09.2023

* Rename `actionListener` parameter to `listener`.

## 1.0.1 - 14.08.2023

* Add example and update README.md.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ With the "Bloc Action Listener", you can achieve this more conveniently.
### 1. Define your actions
You can create the actions as needed. These will be dispatched and can be listened to in the UI.

```
```dart
abstract class ExampleAction {}
class ShowTestDialogAction extends ExampleAction {
Expand All @@ -42,7 +42,7 @@ class ShowSnackbarAction extends ExampleAction {
### 2. Extend your Bloc or Cubit
Use the `BlocActionsMixin` to extend your Bloc or Cubit. This mixin provides the `addAction()` method which allows you to dispatch the defined actions.

```
```dart
class ExampleCubit extends Cubit<ExampleState> with BlocActionsMixin<ExampleState, ExampleAction> {
ExampleCubit() : super(ExampleInitial());
Expand All @@ -63,9 +63,9 @@ class ExampleCubit extends Cubit<ExampleState> with BlocActionsMixin<ExampleStat
## 3. Listen and process actions in the UI
Using the `BlocActionListener` widget, you can respond to the dispatched actions in the UI.

```
```dart
BlocActionListener<ExampleCubit, ExampleAction>(
actionListener: (context, action) {
listener: (context, action) {
if (action is ShowTestDialogAction) {
final title = action.title;
final content = action.content;
Expand Down
2 changes: 1 addition & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class HomePage extends StatelessWidget {
body: BlocProvider(
create: (_) => ExampleCubit(),
child: BlocActionListener<ExampleCubit, ExampleAction>(
actionListener: (context, action) {
listener: (context, action) {
if (action is ShowTestDialogAction) {
final title = action.title;
final content = action.content;
Expand Down
14 changes: 7 additions & 7 deletions lib/bloc_action_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ typedef BlocWidgetActionListener<A> = void Function(BuildContext context, A acti

class BlocActionListener<B extends ActionsStreamable<A>, A> extends BlocActionListenerBase<B, A> {
const BlocActionListener({
required BlocWidgetActionListener<A> actionListener,
required BlocWidgetActionListener<A> listener,
Key? key,
B? bloc,
Widget? child,
}) : super(key: key, child: child, actionListener: actionListener, bloc: bloc);
}) : super(key: key, child: child, listener: listener, bloc: bloc);
}

abstract class BlocActionListenerBase<B extends ActionsStreamable<A>, A>
extends SingleChildStatefulWidget {
const BlocActionListenerBase({
required this.actionListener,
required this.listener,
Key? key,
this.bloc,
this.child,
Expand All @@ -32,12 +32,12 @@ abstract class BlocActionListenerBase<B extends ActionsStreamable<A>, A>
final Widget? child;

/// The [bloc] whose `actions` will be listened to.
/// When a new action is added from [bloc], the [actionListener] will be called
/// When a new action is added from [bloc], the [listener] will be called
final B? bloc;

/// A [BlocWidgetActionListener] listener that will be called on each new `action`.
/// This [actionListener] should be used for any code that needs to be execute
final BlocWidgetActionListener<A> actionListener;
/// This [listener] should be used for any code that needs to be execute
final BlocWidgetActionListener<A> listener;

@override
SingleChildState<BlocActionListenerBase<B, A>> createState() => _BlocListenerBaseState<B, A>();
Expand Down Expand Up @@ -104,7 +104,7 @@ class _BlocListenerBaseState<B extends ActionsStreamable<A>, A>

void _subscribe() {
_subscription = _bloc.actions.listen((state) {
widget.actionListener(context, state);
widget.listener(context, state);
});
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bloc_action_listener
description: Package adds a stream to which you can send actions from your Bloc or Cubit and process these actions on the UI similar to a BlocListener
version: 1.0.1
version: 1.0.2
homepage: https://github.com/LanarsInc/bloc-action-listener

environment:
Expand Down

0 comments on commit 1908992

Please sign in to comment.