A provider that passes EventBus down to all the widgets.

Overview

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

You might also like...

A code generator to write widgets as function without loosing the benefits of classes.

Widgets are cool. But classes are quite verbose: class Foo extends StatelessWidget { final int value; final int value2; const Foo({Key key, thi

Dec 29, 2022

Code generation for Flutter Padding widgets based on your constants

Code generation for Flutter Padding widgets based on your constants

Oct 20, 2022

Animate SliverAppBar's widgets when scrolling

Animate SliverAppBar's widgets when scrolling

Animate SliverAppBar's widgets when scrolling

Oct 2, 2022

This package supports drag & drop widgets inside the GridView.builder for multiplatform

This package supports drag & drop widgets inside the GridView.builder for multiplatform

This package supports drag & drop widgets inside the GridView.builder for multiplatform. It provides all the properties which are available in Gridview. builder and easy to implement with the few lines of code.

Dec 29, 2022

Flutter widgets and themes implementing the current macOS design language.

Flutter widgets and themes implementing the current macOS design language.

macos_ui Flutter widgets and themes implementing the current macOS design language. NOTE: This package depends on the excellent native_context_menu pl

Jan 7, 2023

Flutter Package for Easier Creation of Home Screen Widgets

Flutter Package for Easier Creation of Home Screen Widgets

Home Widget HomeWidget is a Plugin to make it easier to create HomeScreen Widgets on Android and iOS. HomeWidget does not allow writing Widgets with F

Dec 31, 2022

This repo is for anything that can be reusable in flutter like custom widgets 🟥, animations 🌟and more

Flutter Shortcuts This repo is for anything that can be reusable in flutter like custom widgets 🟥 , animations 🌟 and more. How to Use Just get the f

Dec 3, 2022

Library Widgets

Library Widgets

Library Widgets Installing 1. Depend on it Add this to your package's pubspec.yaml file: dependencies: library_widgets: ^0.0.1 2. Install it You can

Oct 28, 2021

A basic Flutter app that includes some native Widgets like alerts, cards, avatars, animated container, inputs, etc.

A basic Flutter app that includes some native Widgets like alerts, cards, avatars, animated container, inputs, etc.

Flutter components This project was created with Flutter and some native Widgets like alerts, cards, avatars, animated container, inputs, etc. Getting

Nov 15, 2021
Comments
  • Feature: View widget

    Feature: View widget

    Meta

    | Name | Description | | -----| ----------- | | Version | 0.1.0 | | Scope | View |

    Problem Statement

    As of now, StreamBuilder is used to consume data from EventBus. This results in repetition of code in initialData and stream. The snapshot data is also checked for null.

    StreamBuilder<BmiViewModel>(
      initialData: context.fetch<BmiViewModel>(),
      stream: context.select<BmiViewModel>(),
      builder: (context, snapshot) => WeightText(
        text: snapshot.data!.weight,
      ),
    ),
    

    Proposed Solution

    A new widget called View can be created to hide this complexity.

    Changes

    1. Create a new widget View.
    2. Create a new widget ViewWithContext to provide context.
    3. Create a new widget DataWidget to facilitate inheritance.
    4. Update tests.
    5. Update example.
    6. Update Readme.
    feature 
    opened by amsakanna 0
  • Feature: Extension methods for BuildContext

    Feature: Extension methods for BuildContext

    Meta

    | Name | Description | | -----| ----------- | | Version | 0.0.1 | | Scope | event_bus_provider |

    Problem Statement

    As of now, EventBus is retrieved from a widget as follows:

    final bus = EventBusProvider.of(context);
    bus.publish(IncrementEvent());
    bus.select<Counter>()
    

    The first line of code is a little bit of extra work every time we need an EventBus.

    Proposed Solution

    We can create an extension method for the BuildContext and use it like this:

    context.dispatch(IncrementEvent());
    context.select<Counter>();
    context.save(Counter());
    context.fetch<Counter>();
    

    Changes

    1. Add EventBusOnBuildContextExtension.
    2. Add DispatchOnBuildContextExtension.
    3. Add PublishOnBuildContextExtension.
    4. Add SelectOnBuildContextExtension.
    5. Add SaveOnBuildContextExtension.
    6. Add FetchOnBuildContextExtension.
    7. Update example.
    8. Update Readme.
    9. Update documentation.
    feature 
    opened by amsakanna 0
  • Feature: EventBusProvider to pass EventBus down to all flutter widgets

    Feature: EventBusProvider to pass EventBus down to all flutter widgets

    Meta

    | Name | Description | | -----| ----------- | | Version | 0.0.1 | | Scope | EventBusProvider |

    Problem Statement

    There is no way a widget can now access EventBus from zam_event_bus package.

    Proposed Solution

    An InheritedWidget can be created to pass the EventBus down the line.

    New Components

    1. EventBusProvider
    feature 
    opened by amsakanna 0
Releases(0.5.1)
Owner
null
Here you will get basic implementation of all useful and top widgets in flutter.

Top Widgets in Flutter This is a common repo where you can get most frequest used widgets in flutter. Samples Getting Started This project is a starti

Sakhawat Hossain 5 Nov 3, 2022
Custom widgets and utils using Flutter framework widgets and Dart language

reuse_widgets_and_utils The custom widgets and utils using Flutter framework widgets and Dart programming language. Getting Started This project is a

null 1 Oct 29, 2021
Flutter package: Assorted layout widgets that boldly go where no native Flutter widgets have gone before.

assorted_layout_widgets I will slowly but surely add interesting widgets, classes and methods to this package. Despite the package name, they are not

Marcelo Glasberg 122 Dec 22, 2022
Flutter-useful-widgets - Flutter Useful Widgets

useful_widgets This package makes it easy to build apps by providing a list of simple and useful widgets. import 'package:useful_widgets/useful_widget

Ricardo Crescenti 6 Jun 20, 2022
Widgets beginner - Widgets beginner with flutter

Widgets beginner - Widgets beginner with flutter

Tukhtamurodov Sardorbek 2 Feb 6, 2022
Provider support for overlay, make it easy to build toast and In-App notification.

overlay_support Provider support for overlay, make it easy to build toast and In-App notification. this library support ALL platform Interaction If yo

Bin 340 Jan 1, 2023
Unofficial search provider for Medium for dart/flutter apps.

medium_search Unofficial search provider for Medium that can be used in dart or flutter apps. This library provides you an easy way to get search resu

Clone Conflict 1 Jan 10, 2022
A light-weight Emoji 📦 for Dart & Flutter with all up-to-date emojis written in pure Dart 😄 . Made from 💯% ☕ with ❤️!

dart_emoji ?? A light-weight Emoji ?? for Dart & Flutter with all up-to-date emojis written in pure Dart ?? . Made from ?? % ☕ with ❤️ ! This is a for

Gatch 18 Mar 22, 2022
An advanced flutter package to build responsive application accross all platform with ease and has an handful of different types of extension

Flutter Next Now build flutter apps with ease and responsive. An advanced flutter package to build responsive application accross all platform with ea

Shashi Kumar 10 Dec 29, 2022
React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.

English | Português Flutter Hooks A Flutter implementation of React hooks: https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889 Ho

Remi Rousselet 2.6k Dec 29, 2022