bsev 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

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 IncrementEvent extends EventsBase{}

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>{

  //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());
  
  // If you need send event to all BloCs
  //dispatchAll(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)
    }
    
  }
}

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: (event, communication){ //optional
        // performs action received by the bloc
      },
      builder: (context,communication){
      
          return Scaffold(
            appBar: AppBar(),
            body: communication.streams.count.builder<int>((value) {
                return Text(value.toString());
            }),
            floatingActionButton: FloatingActionButton(
                onPressed: (){
                  communication.dispatcher(IncrementEvent());
                }
            ),
          );
      
      }
    );
    
  }
  
}

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

  MyApp(){

    registerBloc<HomeBloc, HomeStreams>((i) => HomeBloc(), () => HomeStreams());

    //Example of the register any things.
    //registerDependency((i) => CryptoRepository(i.getDependency()));

    //Example of the register any things Singleton.
    //registerSingleton((i) => CryptoRepository(i.getDependency()));

    //Example get dependency anywhere
    //var dependency = getDependency<CryptoRepository>();
    
  }

Questions about how to use the injector consult documentation.

More complex example is found here

Testing HomeBloc #

import 'package:flutter_test/flutter_test.dart';

void main() {
  HomeBloc _homeBloc;
  HomeStreams _homeStreams;

  setUp(() {
    _homeStreams = HomeStreams();
    _homeBloc = HomeBloc()..streams = _homeStreams;
  });

  tearDown(() {
    _homeBloc?.dispose();
  });
  
  test('initial streams', () {
    expect(_homeStreams.count.value, 0);
  });
  
  test('increment value', () {
    _homeBloc.eventReceiver(IncrementEvent());
    expect(_homeStreams.count.value, 1);
  });

  test('increment value 3 times', () {
    _homeBloc.eventReceiver(IncrementEvent());
    _homeBloc.eventReceiver(IncrementEvent());
    _homeBloc.eventReceiver(IncrementEvent());
    expect(_homeStreams.count.value, 3);
  });
  
}

Test example with asynchronous call: here

Used packages #

Packagespub
rxdartPub
injectorPub

User cases #

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

[1.0.1] - 21/02/2020 #

  • export rxdart

[1.0.0] - 16/02/2020 #

Breaking Changes: #

  • 'eventReceiver: (context, event, dispatcher)' in Bsev Widget to 'eventReceiver: (event, communication)';
  • 'builder: (context, dispatcher, streams)' in Bsev Widget to 'builder: (context,communication)';
  • add extension in BaseStreams called 'builder' or use StreamListener to build your view.

[0.9.3] - 8/02/2020 #

  • add getDependency

[0.9.2] - 8/02/2020 #

  • fix conflict imports streamBuilder

[0.9.1] - 27/01/2020 #

  • add registerSingleton

[0.9.0] - 27/01/2020 #

  • add dispatcherAll
  • add methods to inject BloCs and dependencies
  • add StreamListener

[0.8.7] - 26/09/2019 #

  • removes need for custom EventBase

[0.8.6] - 15/09/2019 #

  • version without context in Bloc

[0.8.5] - 15/09/2019 #

  • update rxdart
  • version with context in Bloc

[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/lib/main.dart

import 'package:bsev/flavors.dart';
import 'package:bsev_demo/di/initDependencies.dart';
import 'package:bsev_demo/screens/home/HomeView.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  MyApp() {
    WidgetsFlutterBinding.ensureInitialized();
    Flavors.configure(Flavor.PROD);
    initDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomeView(),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  bsev: ^1.0.1

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]
83
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Apr 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-0.59 points)

144 out of 146 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
injector ^1.0.8 1.0.8
rxdart ^0.23.1 0.23.1 0.24.0-dev.1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test