Widgets that make it easy to integrate blocs and cubits into Flutter. Built to work with package:bloc.
BLOCS 2.0.1 May 12, 2016 Fixed. Fixed issue that caused site options to crash with 1.6 projects. Fixed issue that caused app to crash when deleting a global swatch. Fixed issue that caused form php files to not be generated on export.
BLOC 3 PRISES AVEC INTERRUPTEUR PROTECTION ENFANTS HO5VVF 3G1.0 ELE100 Page catalogue: 2449 Suremballage: 40 En stock -+ Vendu par. Bloc has 115 repositories available. Follow their code on GitHub. Skip to content. JavaScript Apache-2.0 40 11 1 0 Updated Jul 28, 2017. Messenger This is a small app to message using the Bloc Api JavaScript 3 7 18 (6 issues need help) 0 Updated Jul 17, 2017. EBay Bloc LocHalf Square Triangle Ruler Set #1-1.5',2.5',3.5',4.5',5.5', 6.5', Acrylic Ruler PRODUCT DESCRIPTION Bloc Loc's half square triangle rulers make the tough job of squaring up easy and fast. The groove slides along the seam to trim smaller units and allows quilters to. Blocs for Mac is a fast, easy-to-use, powerful visual web-design tool that lets you create beautiful, modern websites without the need to write code. Cleverly designed to accommodate complete beginners or those familiar with web design.
Learn more at bloclibrary.dev!
*Note: All widgets exported by the flutter_bloc
package integrate with both Cubit
and Bloc
instances.
Sponsors #
Our top sponsors are shown below! [Become a Sponsor]
Try the Flutter Chat Tutorial 💬 |
Usage #
Lets take a look at how to use BlocBuilder
to hook up a CounterPage
widget to a CounterCubit
.
counter_cubit.dart #
counter_page.dart #
At this point we have successfully separated our presentational layer from our business logic layer. Notice that the CounterPage
widget knows nothing about what happens when a user taps the buttons. The widget simply tells the CounterCubit
that the user has pressed either the increment or decrement button.
Bloc Widgets #
BlocBuilder #
BlocBuilder is a Flutter widget which requires a cubit
and a builder
function. BlocBuilder
handles building the widget in response to new states. BlocBuilder
is very similar to StreamBuilder
but has a more simple API to reduce the amount of boilerplate code needed. The builder
function will potentially be called many times and should be a pure function that returns a widget in response to the state.
See BlocListener
if you want to 'do' anything in response to state changes such as navigation, showing a dialog, etc..
If the cubit parameter is omitted, BlocBuilder
will automatically perform a lookup using BlocProvider
and the current BuildContext
.
Only specify the cubit if you wish to provide a cubit that will be scoped to a single widget and isn't accessible via a parent BlocProvider
and the current BuildContext
.
For fine-grained control over when the builder
function is called an optional buildWhen
can be provided. buildWhen
takes the previous cubit state and current cubit state and returns a boolean. If buildWhen
returns true, builder
will be called with state
and the widget will rebuild. If buildWhen
returns false, builder
will not be called with state
and no rebuild will occur.
BlocProvider #
BlocProvider is a Flutter widget which provides a cubit to its children via BlocProvider.of(context)
. It is used as a dependency injection (DI) widget so that a single instance of a cubit can be provided to multiple widgets within a subtree.
In most cases, BlocProvider
should be used to create new cubits which will be made available to the rest of the subtree. In this case, since BlocProvider
is responsible for creating the cubit, it will automatically handle closing it.
By default, BlocProvider will create the cubit lazily, meaning create
will get executed when the cubit is looked up via BlocProvider.of(context)
.
To override this behavior and force create
to be run immediately, lazy
can be set to false
.
In some cases, BlocProvider
can be used to provide an existing cubit to a new portion of the widget tree. This will be most commonly used when an existing cubit
needs to be made available to a new route. In this case, BlocProvider
will not automatically close the cubit since it did not create it.
then from either ChildA
, or ScreenA
we can retrieve BlocA
with:
The above snippets result in a one time lookup and the widget will not be notified of changes. To retrieve the instance and subscribe to subsequent state changes use:
In addition, context.select
can be used to retrieve part of a state and react to changes only when the selected part changes.
The snippet above will only rebuild if the state of the CounterBloc
changes from positive to negative or vice versa.
*Note: All widgets exported by the flutter_bloc
package integrate with both Cubit
and Bloc
instances.
Sponsors #
Our top sponsors are shown below! [Become a Sponsor]
Try the Flutter Chat Tutorial 💬 |
Usage #
Lets take a look at how to use BlocBuilder
to hook up a CounterPage
widget to a CounterCubit
.
counter_cubit.dart #
counter_page.dart #
At this point we have successfully separated our presentational layer from our business logic layer. Notice that the CounterPage
widget knows nothing about what happens when a user taps the buttons. The widget simply tells the CounterCubit
that the user has pressed either the increment or decrement button.
Bloc Widgets #
BlocBuilder #
BlocBuilder is a Flutter widget which requires a cubit
and a builder
function. BlocBuilder
handles building the widget in response to new states. BlocBuilder
is very similar to StreamBuilder
but has a more simple API to reduce the amount of boilerplate code needed. The builder
function will potentially be called many times and should be a pure function that returns a widget in response to the state.
See BlocListener
if you want to 'do' anything in response to state changes such as navigation, showing a dialog, etc..
If the cubit parameter is omitted, BlocBuilder
will automatically perform a lookup using BlocProvider
and the current BuildContext
.
Only specify the cubit if you wish to provide a cubit that will be scoped to a single widget and isn't accessible via a parent BlocProvider
and the current BuildContext
.
For fine-grained control over when the builder
function is called an optional buildWhen
can be provided. buildWhen
takes the previous cubit state and current cubit state and returns a boolean. If buildWhen
returns true, builder
will be called with state
and the widget will rebuild. If buildWhen
returns false, builder
will not be called with state
and no rebuild will occur.
BlocProvider #
BlocProvider is a Flutter widget which provides a cubit to its children via BlocProvider.of(context)
. It is used as a dependency injection (DI) widget so that a single instance of a cubit can be provided to multiple widgets within a subtree.
In most cases, BlocProvider
should be used to create new cubits which will be made available to the rest of the subtree. In this case, since BlocProvider
is responsible for creating the cubit, it will automatically handle closing it.
By default, BlocProvider will create the cubit lazily, meaning create
will get executed when the cubit is looked up via BlocProvider.of(context)
.
To override this behavior and force create
to be run immediately, lazy
can be set to false
.
In some cases, BlocProvider
can be used to provide an existing cubit to a new portion of the widget tree. This will be most commonly used when an existing cubit
needs to be made available to a new route. In this case, BlocProvider
will not automatically close the cubit since it did not create it.
then from either ChildA
, or ScreenA
we can retrieve BlocA
with:
The above snippets result in a one time lookup and the widget will not be notified of changes. To retrieve the instance and subscribe to subsequent state changes use:
In addition, context.select
can be used to retrieve part of a state and react to changes only when the selected part changes.
The snippet above will only rebuild if the state of the CounterBloc
changes from positive to negative or vice versa.
MultiBlocProvider #
MultiBlocProvider is a Flutter widget that merges multiple BlocProvider
widgets into one.MultiBlocProvider
improves the readability and eliminates the need to nest multiple BlocProviders
.By using MultiBlocProvider
we can go from:
to:
BlocListener #
BlocListener is a Flutter widget which takes a BlocWidgetListener
and an optional cubit
and invokes the listener
in response to state changes in the cubit. It should be used for functionality that needs to occur once per state change such as navigation, showing a SnackBar
, showing a Dialog
, etc..
listener
is only called once for each state change (NOT including the initial state) unlike builder
in BlocBuilder
and is a void
function.
If the bloc parameter is omitted, BlocListener
will automatically perform a lookup using BlocProvider
and the current BuildContext
.
Only specify the cubit if you wish to provide a cubit that is otherwise not accessible via BlocProvider
and the current BuildContext
.
For fine-grained control over when the listener
function is called an optional listenWhen
can be provided. listenWhen
takes the previous cubit state and current cubit state and returns a boolean. If listenWhen
returns true, listener
will be called with state
. If listenWhen
returns false, listener
will not be called with state
.
MultiBlocListener #
MultiBlocListener is a Flutter widget that merges multiple BlocListener
widgets into one.MultiBlocListener
improves the readability and eliminates the need to nest multiple BlocListeners
.By using MultiBlocListener
we can go from:
to:
Blocs 3 1 0 141
BlocConsumer #
BlocConsumer exposes a builder
and listener
in order react to new states. BlocConsumer
is analogous to a nested BlocListener
and BlocBuilder
but reduces the amount of boilerplate needed. BlocConsumer
should only be used when it is necessary to both rebuild UI and execute other reactions to state changes in the cubit
. BlocConsumer
takes a required BlocWidgetBuilder
and BlocWidgetListener
and an optional cubit
, BlocBuilderCondition
, and BlocListenerCondition
.
If the cubit
parameter is omitted, BlocConsumer
will automatically perform a lookup usingBlocProvider
and the current BuildContext
.
An optional listenWhen
and buildWhen
can be implemented for more granular control over when listener
and builder
are called. The listenWhen
and buildWhen
will be invoked on each cubit
state
change. They each take the previous state
and current state
and must return a bool
which determines whether or not the builder
and/or listener
function will be invoked. The previous state
will be initialized to the state
of the cubit
when the BlocConsumer
is initialized. listenWhen
and buildWhen
are optional and if they aren't implemented, they will default to true
.
RepositoryProvider #
RepositoryProvider is a Flutter widget which provides a repository to its children via RepositoryProvider.of(context)
. It is used as a dependency injection (DI) widget so that a single instance of a repository can be provided to multiple widgets within a subtree. BlocProvider
should be used to provide blocs whereas RepositoryProvider
should only be used for repositories.
Adobe xd windows 7. then from ChildA
we can retrieve the Repository
instance with:
MultiRepositoryProvider #
MultiRepositoryProvider is a Flutter widget that merges multiple RepositoryProvider
widgets into one.MultiRepositoryProvider
improves the readability and eliminates the need to nest multiple RepositoryProvider
.By using MultiRepositoryProvider
we can go from:
to:
Gallery #
Examples #
- Counter - an example of how to create a
CounterBloc
to implement the classic Flutter Counter app. - Form Validation - an example of how to use the
bloc
andflutter_bloc
packages to implement form validation. - Bloc with Stream - an example of how to hook up a
bloc
to aStream
and update the UI in response to data from theStream
. - Complex List - an example of how to manage a list of items and asynchronously delete items one at a time using
bloc
andflutter_bloc
. - Infinite List - an example of how to use the
bloc
andflutter_bloc
packages to implement an infinite scrolling list. - Login Flow - an example of how to use the
bloc
andflutter_bloc
packages to implement a Login Flow. - Firebase Login - an example of how to use the
bloc
andflutter_bloc
packages to implement login via Firebase. - Github Search - an example of how to create a Github Search Application using the
bloc
andflutter_bloc
packages. - Weather - an example of how to create a Weather Application using the
bloc
andflutter_bloc
packages. The app uses aRefreshIndicator
to implement 'pull-to-refresh' as well as dynamic theming. - Todos - an example of how to create a Todos Application using the
bloc
andflutter_bloc
packages. - Timer - an example of how to create a Timer using the
bloc
andflutter_bloc
packages. - Firestore Todos - an example of how to create a Todos Application using the
bloc
andflutter_bloc
packages that integrates with cloud firestore. - Shopping Cart - an example of how to create a Shopping Cart Application using the
bloc
andflutter_bloc
packages based on flutter samples. - Dynamic Form - an example of how to use the
bloc
andflutter_bloc
packages to implement a dynamic form which pulls data from a repository. - Wizard - an example of how to build a multi-step wizard using the
bloc
andflutter_bloc
packages. - GraphQL - an example of how to use the
bloc
andflutter_bloc
packages withgraphql
to retrieve data from api.graphql.jobs. - Fluttersaurus - an example of how to use the
bloc
andflutter_bloc
packages to create a thesuarus app -- made for Bytconf Flutter 2020.
Dart Versions #
- Dart 2: >= 2.6.0
Maintainers #
A dart package that helps implement the BLoC pattern.
Learn more at bloclibrary.dev!
This package is built to work with:
Overview #
The goal of this package is to make it easy to implement the BLoC
Design Pattern (Business Logic Component).
This design pattern helps to separate presentation from business logic. Following the BLoC pattern facilitates testability and reusability. This package abstracts reactive aspects of the pattern allowing developers to focus on writing the business logic.
Cubit #
A Cubit
is the base for Bloc
(in other words Bloc
extends Cubit
). Cubit
is a special type of Stream
which can be extended to manage any type of state. Cubit
requires an initial state which will be the state before emit
has been called. The current state of a cubit
can be accessed via the state
getter and the state of the cubit
can be updated by calling emit
with a new state
.
State changes in cubit begin with predefined function calls which can use the emit
method to output new states. onChange
is called on each state change and contains the current and next state.
Creating a Cubit
Using a Cubit
Observing a Cubit
onChange
can be overridden to observe state changes for a single cubit
.
onError
can be overridden to observe errors for a single cubit
.
BlocObserver
can be used to observe all cubits
.
Bloc #
A Bloc
is a more advanced type of Cubit
which relies on events
to trigger state
changes rather than functions. Bloc
extends Cubit
which means it has the same public API as Cubit
. However, rather than calling a function
on a Bloc
and directly emitting a new state
, Blocs
receive events
and convert the incoming events
into outgoing states
.
State changes in bloc begin when events are added which triggers onEvent
. The events are then funnelled through transformEvents
. By default, transformEvents
uses asyncExpand
to ensure each event is processed in the order it was added but it can be overridden to manipulate the incoming event stream. mapEventToState
is then invoked with the transformed events and is responsible for yielding states in response to the incoming events. transitions
are then funnelled through transformTransitions
which can be overridden to manipulation the outgoing state changes. Lastly, onTransition
is called just before the state is updated and contains the current state, event, and next state.
Creating a Bloc
Using a Bloc
Observing a Bloc
Since all Blocs
are Cubits
, onChange
and onError
can be overridden in a Bloc
as well.
In addition, Blocs
can also override onEvent
and onTransition
.
Blocs 3 1 0 10
onEvent
is called any time a new event
is added to the Bloc
.
onTransition
is similar to onChange
, however, it contains the event
which triggered the state change in addition to the currentState
and nextState
.
BlocObserver
can be used to observe all blocs
as well.
Dart Versions #
- Dart 2: >= 2.6.0
Examples #
- Counter - an example of how to create a
CounterBloc
in a pure Dart app.