Skip to content

Flutterando/builders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

builders

Use Consumer, Select and BlocConsumer in any System Injector

How Install

Open your project's pubspec.yaml and add flutter_modular as a dependency:

dependencies:
  builders: any

You can also provide the git repository as source instead, to try out the newest features and fixes:

dependencies:
  builders:
    git:
      url: https://github.com/Flutterando/builders

Configure your System Injector

You can use any System Injector for example Modular or Get_it.

main(){
    
    //using Modular
    Builders.systemInjector(Modular.get);
    
    //using Get_it
    Builders.systemInjector(GetIt.I.get);

    runApp(YourAmazingApp());
}

Using in your Flutter App

Here are some Builders known to the community. Here we have Consumer and Selector (Originally from the Provider package) and BlocConsumer, (from the flutter_bloc package)

Consumer

Consumer is used when you want to listen to a class that extends from ChangeNotifier:

class MyCounter extends ChangeNotifier {

    int value;

    increment() {
        value++;
        notifyListeners();
    }

}

in your View:

Consumer<MyCounter>(
    builder: (context, myCounter){
        return Text('${myCounter.value}');
    }
);

Selector

Selector works like Consumers, however you can select and listen to only one property of your Object.

Selector<MyCounter, int>(
    selector: (myCounter) => myCounter.value,
    builder: (context, value){
        return Text('$value');
    }
);

BlocConsumer

Listen to custom streams from the bloc package (Bloc and Cubit).

class MyCounterBloc extends Cubit<int> {

    MyCounterBloc(): super(0);

    increment() => emit(state + 1);

}

in your View:

BlocConsumer<MyCounterBloc, int>(
    builder: (context, state){
        return Text('$state');
    }
);

Features and bugs

Please send feature requests and bugs at the issue tracker.

This README was created based on templates made available by Stagehand under a BSD-style license.

About

Use Consumer, Select and BlocConsumer in any System Injector

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •