bloc_generic_streams 1.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

Bloc Generic Streams #

This package was create to be an easy implementation of Didier Boelens's BlocProvider and including a new way to use a BehaviorSubject using GenericStream class that creates an object more simple with Dart's Generics.

I built this package because when you have an application like an Uber application, which was my case, others bloc packages didn't attended my expectations, so, I created this, more simple and more intuitive. You only need to create your Bloc extending BlocBase and then creating a BlocProvider in whatever screen you desire.

Example: #

    import 'package:bloc_generic_streams/bloc_generic_streams.dart';
    
    class HomeBloc extends BlocBase {
      int counter = 0;
      final GenericBehavior<int> counterStream = GenericBehavior<int>();

      // Other Subjects

      //final GenericPublish<int> publishSubject = GenericPublish<int>();

      //final GenericReplay<int> publishSubject = GenericReplay<int>();
    
      void increment() {
        counterStream.sink(++counter);
      }
    
      @override
      void dispose() {
        counterStream?.dispose();
      }
    }

counterStream variable contains all most important methods exposed, like:

  • sink (StreamSink)
  • stream (ValueStream)
  • stream debounce (1500 ms)

How to use BlocProvider? #

class HomeScreen extends StatelessWidget {
	//Instantiate our bloc... HomeBloc in our case
      final HomeBloc _bloc = HomeBloc();
    
      @override
      Widget build(BuildContext context) {
	  //Return a BlocProvider instance specifying its type
        return BlocProvider<HomeBloc>(
          blocBuilder: () => _bloc, // Build and create our bloc
          child: Scaffold(
            appBar: AppBar(title: Text('Home Screen')),
            floatingActionButton: FloatingActionButton(
              onPressed: _bloc.increment,
              child: Icon(Icons.add),
            ),
            body: Center(
              child: StreamBuilder<int>(
                initialData: _bloc.counter,
                //Retrieving Stream from _bloc's GenericStream object
                stream: _bloc.counterStream.stream,
                builder: (_, AsyncSnapshot<int> snapshot) {
                  return Text(
                    '${snapshot.data}',
                    style: Theme.of(context).textTheme.display1,
                  );
                },
              ),
            ),
          ),
        );
      }
    }

Now it's very easy to implement a BLoC class and to manipulate the way you want.

Retrieving Bloc #

Follow the same pattern from other packages, like this:

final HomeBloc _bloc = BlocProvider.of<HomeBloc>(context);

With that, you can access and retrieved any stream/method inside your Bloc.

__

[1.3.0] - 17/03/2020 #

  • Removed BlocDisposer param.

[1.2.1] - 14/03/2020 #

  • Updated README.md

[1.2.0] - 14/03/2020 #

  • Added PublishSubject & ReplaySubject
  • Updated to GenericBehavior, GenericPublish & GenericReplay

[1.0.8] - 26/02/2020 #

  • Updated README.md and added MIT license

[1.0.2] - 26/02/2020 #

  • Refactor GenericBloc class to GenericStream class

[1.0.1] - 26/02/2020 #

  • Make some unnecessary fields private

[1.0.0] - 26/02/2020 #

  • Fully working

[0.0.1] - 26/02/2020. #

  • Implememented Didier Booleans Provider.

example/main.dart

import 'package:flutter/material.dart';

import 'src/home_screen/home_screen.dart';

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

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: HomeScreen());
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  bloc_generic_streams: ^1.3.0

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:bloc_generic_streams/bloc_generic_streams.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
54
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Mar 27, 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.09 points)

31 out of 32 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.1.0 <3.0.0
flutter 0.0.0
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