mono_bloc_flutter 1.0.0 copy "mono_bloc_flutter: ^1.0.0" to clipboard
mono_bloc_flutter: ^1.0.0 copied to clipboard

Flutter widgets and utilities for mono_bloc. Provides MonoBlocActionListener for handling side effects in Flutter apps.

mono_bloc_flutter #

pub version Tests

Flutter widgets and utilities for MonoBloc. Provides MonoBlocActionListener for handling side effects in Flutter apps.

Installation #

dependencies:
  mono_bloc_flutter: ^1.0.0

What's Included #

This package exports everything you need for using MonoBloc in Flutter:

  • MonoBlocActionListener - Widget for listening to bloc actions
  • All of flutter_bloc - BlocProvider, BlocBuilder, BlocListener, etc.
  • All of mono_bloc - Annotations, base classes, and core functionality

You only need one import:

import 'package:mono_bloc_flutter/mono_bloc_flutter.dart';

Usage #

Define your bloc with actions #

part 'cart_bloc.g.dart';

@MonoBloc()
abstract class CartBloc extends _$CartBloc<CartState> {
  CartBloc._() : super(const CartState());
  factory CartBloc() = _$CartBlocImpl;

  @event
  CartState _onCheckout() {
    if (state.items.isNotEmpty) {
      navigateToCheckout();
    }
    return state.copyWith(items: []);
  }

  @action
  void navigateToCheckout();
}

Listen to actions in your widget #

Option 1: Implement the actions interface

class CartPage extends StatelessWidget implements CartBlocActions {
  const CartPage({super.key});

  @override
  Widget build(BuildContext context) {
    return CartBlocActionListener(
      actions: CartBlocActions.of(this),
      child: CartView(),
    );
  }

  @override
  void navigateToCheckout(BuildContext context) {
    Navigator.pushNamed(context, '/checkout');
  }
}

Option 2: Use inline actions with .when()

class CartPage extends StatelessWidget {
  const CartPage({super.key});

  @override
  Widget build(BuildContext context) {
    return CartBlocActionListener(
      actions: CartBlocActions.when(
        navigateToCheckout: (context) {
          Navigator.pushNamed(context, '/checkout');
        },
      ),
      child: CartView(),
    );
  }
}

Features #

MonoBlocActionListener #

A Flutter widget that listens to actions from a MonoBloc and automatically provides BuildContext to action handlers.

Key benefits:

  • ✅ Automatic subscription management (subscribe/unsubscribe)
  • ✅ BuildContext automatically provided to all action handlers
  • ✅ Type-safe action handling with generated interfaces
  • ✅ Two usage patterns: interface implementation or inline callbacks
  • ✅ Integrates seamlessly with BlocProvider

FlutterMonoBlocActions #

Base class for generated action handlers in Flutter. Automatically included in generated code when using @action annotations.

Documentation #

For complete documentation, examples, and guides:

License #

MIT License - see the LICENSE file for details.

0
likes
0
points
75
downloads

Publisher

verified publisherwestito.dev

Weekly Downloads

Flutter widgets and utilities for mono_bloc. Provides MonoBlocActionListener for handling side effects in Flutter apps.

Repository (GitHub)
View/report issues

Topics

#bloc #flutter #state-management

License

unknown (license)

Dependencies

flutter, flutter_bloc, meta, mono_bloc

More

Packages that depend on mono_bloc_flutter