iYadavVaibhav / counter_bloc

Flutter app build using Bloc architecture showing counter increment and decrement.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hello! This flutter app demonstrates BLoC library and Flutter_Bloc library. It shows very simple example of counter app implemented using bloc state architecture pattern.

The workflow of the Counter App:

  • add packages
  • create events as enum.
  • create state - in this app, state is int so we don't create state class.
  • create bloc to take events, map it, and return state,
    • class CounterBloc extends Bloc<CounterEvent, int> {...}
    • here override init state
    • and override mapEventsToState
  • instantiate bloc in main using BlocProvider<Bloc>{}.
  • create Page, get bloc,
  • get bloc, final CounterBloc counterBloc = BlocProvider.of<CounterBloc>(context);
  • body will be BlocBuilder<CounterBloc, int>(); to build UI based on state.
  • action event, onPressed: () {counterBloc.add(CounterEvent.increment);}

The Counter_Bloc app is developed based on Flutter Counter App tutorial by @felangel.

Thank you.

About

Flutter app build using Bloc architecture showing counter increment and decrement.


Languages

Language:Dart 74.6%Language:Kotlin 12.4%Language:Swift 12.0%Language:Objective-C 1.1%