bsev 0.8.4

pub package

BSEV (BloC,Streams,Events,View) #

Set of packages and utilitarian functions that help in the use of BloC pattern with dependency injection.

With bsev you will use the Bloc pattern in a simple, reactive and organized way. Communication between the business logic and the view occurs entirely through two-way streams.

fluxo_bsev

Usage #

To use this plugin, add bsev as a dependency in your pubspec.yaml file.

We should initially create the class that represents our Streams and Events:

Streams #

import 'package:bsev/bsev.dart';

class HomeStreams extends StreamsBase{

  var count = BehaviorSubjectCreate<Int>(initValue: 0);
  //var count = StreamCreate<Int>();
  //var count = PublishSubjectCreate<Int>();
  //var count = ReplaySubjectCreate<Int>();

  @override
  void dispose() {
    count.close();
  }

}

Events #

import 'package:bsev/bsev.dart';

class HomeEvents extends EventsBase{}

class IncrementEvent extends HomeEvents{}

Now we can create our Bloc, class that will be centralized the business rule.

Bloc #

import 'package:bsev/bsev.dart';

class HomeBloc extends BlocBase<HomeStreams,HomeEvents>{

  //If you need to communicate with some instantiated BloC, regardless of whether part of your tree of widgets can use:
  //dispatchToBloc<OtherBloc>(MsgEvent());
  
  //If you need to send an event to the view:
  //dispatchView(MyEvent());

  @override
  void initView() {
  }
  
  @override
  void eventReceiver(EventsBase event) {
  
  // called when the Bloc receives an event
  
    if(event is IncrementEvent){
      streams.count.set(streams.count.value + 1)
    }
    
  }
}

Note: If you do not want to use events (for a screen that only starts, loads and displays data) you can use EventsBase as an event. Ex: BlocBase <HomeStreams, EventsBase>

In our bloc we have 2 mandatory methods: initState and eventReceiver:

initView: In the first buildView this method is invoked;

eventReceiver: Invoked whenever the pad receives an event;

View #

import 'package:bsev/bsev.dart';

class HomeView extends StatelessWidget{
  
  @override
  Widget build(BuildContext context) {
    
    return Bsev<HomeBloc,HomeStreams>(
      dataToBloc: "any data", //optional initial data to bloc
      eventReceiver: (context, event, dispatcher){ //optional
        // performs action received by the bloc
      },
      builder: (context, dispatcher, streams){
      
          return Scaffold(
            appBar: AppBar(),
            body: _buildBody(streams),
            floatingActionButton: FloatingActionButton(
                onPressed: (){
                  dispatcher(IncrementEvent());
                }
            ),
          );
      
      }
    );
    
  }
    
  Widget _buildBody(HomeStreams streams) {

    return StreamBuilder(
      stream: streams.count.get,
      initialData: 0,
      builder: (_,snapshot){

        int count = 0;
        if(snapshot.hasData){
          count = snapshot.data;
        }

        return Center(
          child: Text(count.toString())
        )
      }
    );

  }
  
}

As our Bloc and our StreamsBase will be injected automatically, we should configure it in the Injector in the main of our application:

  MyApp(){

    var injector = Injector.appInstance;
    injector.registerDependency((i)=> HomeBloc());
    injector.registerDependency((i)=> HomeStreams());
    
  }

Questions about how to use the injector consult documentation.

More complex example is found here: exemplo

Used packages #

Packagespub
rxdartPub
injectorPub

User cases #

--------- | FlutterNews | DartLangBr |

[0.8.4] - 14/06/2019

  • update example
  • remove access context in bloc

[0.8.3] - 17/06/2019

  • add context in eventReceiver

[0.8.2] - 14/06/2019

  • remove need from package provider

[0.8.1] - 14/06/2019

  • Otimizations

[0.8.0] - 14/06/2019

  • Version with Widget

[0.7.1] - 12/06/2019

  • Remove context from view in bloc

[0.7.0] - 12/06/2019

  • Fix bug dispatcher multiple instance same bloc

[0.6.5] - 15/05/2019

  • Remove context from view in bloc

[0.6.1] - 15/05/2019

  • Fixin warns pub

[0.6.0] - 15/05/2019

  • Optimizations BlocViewMixin

[0.5.5] - 15/05/2019

  • Optimizations BlocView

[0.5.0] - 15/05/2019

  • ADD Dispatcher

[0.1.0] - 15/05/2019

  • ADD provider
  • Optimizations

[0.0.5] - 11/05/2019

  • ADD injector

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/README.md

bsev_demo #

A new Flutter application.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bsev: ^0.8.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bsev/bsev.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
86
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-0.69 points)

94 out of 95 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/bsev.dart. (-0.50 points)

Analysis of lib/bsev.dart reported 1 hint:

line 20 col 7: This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: Bsev.builderInner

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (rxdart).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
injector ^1.0.8 1.0.8
rxdart ^0.21.0 0.21.0 0.22.1+1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test