zam_event_bus_provider

Creator: coderz1093

Last updated:

0 purchases

zam_event_bus_provider Image
zam_event_bus_provider Images
Add to Cart

Description:

zam event bus provider

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.

EventBusProvider

Check out all the components in detail here
How to use #
Step 1: Create an EventBus #
final bus = EventBus(transformers);
copied to clipboard
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);
copied to clipboard
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),
),
copied to clipboard
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,
),
)
copied to clipboard
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,
);
},
)
copied to clipboard
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,
);
}
}
copied to clipboard
To learn more, move on to the example section or check out these dedicated examples in github.
Status #

Contributors #

Amsakanna

License #
BSD 3-Clause License

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.