zam_event_bus_provider 0.5.1 copy "zam_event_bus_provider: ^0.5.1" to clipboard
zam_event_bus_provider: ^0.5.1 copied to clipboard

A provider for flutter that passes EventBus down to all the widgets.

Event Bus Provider #

A flutter provider that passes EventBus down to all the widgets.

NOTE: This package is an extension to zam_event_bus.

What's inside the package #

Includes the following core components.

Check out all the components in detail here

How to use #

Step 1: Create an EventBus #

final bus = EventBus(transformers);

EventBus is from zam_event_bus package.

Step 2: Provide the EventBus #

final app = EventBusProvider(
  bus: bus,
  child: MaterialApp(
    home: MyHomePage(title: 'Event Bus Demo'),
  ),
);
runApp(app);  

Add EventBusProvider before MaterialApp so that it is made available to all the routes.

Step 3: Use context to dispatch events #

FloatingActionButton(
  onPressed: () => context.dispatch(IncrementEvent()),
  tooltip: 'Increment',
  child: const Icon(Icons.add),
),

Step 4: Wrap your widget with View widget to listen to data #

View<Counter>(
  builder: (data) => Text(
    data.value.toString(),
    style: Theme.of(context).textTheme.headline4,
  ),
)

You can also use StreamBuilder to listen to data.

StreamBuilder<Counter>(
  initialData: context.fetch<Counter>(),
  stream: context.select<Counter>(),
  builder: (context, snapshot) {
    final counterText = snapshot.data!.value.toString();
    return Text(
      counterText,
      style: Theme.of(context).textTheme.headline4,
    );
  },
)

Or you can create a widget extending DataWidget.

class CounterText extends DataWidget<Counter> {
  @override
  Widget buildUsingData(BuildContext context, Counter data) {
    return Text(
      'Inheritance: ${data.value.toString()}',
      style: Theme.of(context).textTheme.headline4,
    );
  }
}

To learn more, move on to the example section or check out these dedicated examples in github.

Status #

Build

Contributors #

License #

BSD 3-Clause License

0
likes
160
points
29
downloads

Publisher

verified publisherzamstation.com

Weekly Downloads

A provider for flutter that passes EventBus down to all the widgets.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, zam_core, zam_event_bus

More

Packages that depend on zam_event_bus_provider