state_bloc 0.0.3 copy "state_bloc: ^0.0.3" to clipboard
state_bloc: ^0.0.3 copied to clipboard

outdated

A new Flutter package.

state_bloc #

pub package

StateBloc help the Widget tree to rebuild again with the help of streams. You do no need to create any bloc class for managing state, just need to instantiating the StateBloc class with an initial value.

Getting Started #

In your flutter project add the dependency:

state_bloc :  0.0.3

For help getting started with Flutter, view the online documentation.

Usage Example

import 'package:state_bloc/state_bloc.dart';

Define a StateBloc #

//Requires a initial value in it's constructor 
StateBloc<int> counterBloc = StateBloc<int>(0);

Listen to Data using BlocBuilder #

//Define the Generics eg : int, String, Foo.
BlocBuilder<int>(
  stateBloc: counterBloc,
  widget: (int value) {
    return Text("$value");
  },
)

Change the state of the bloc #

1. Change the state when you have no access of the value #

This will provide you the previous state data present in the bloc other vise the state you have provided while instantiating the StateBloc

stateBloc.changeState(state: (value) {

  //do changes with value and return it
      return value;

});

2. Change the state without value provided #

stateBloc.changeStateWithoutValueProvided(value);

Listen to the value changed #

stateBloc.listenToValue(listenToValue: (int value) {

  //listen to the value when changed

});