dash 0.4.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new75

Dash #

Logo

Dash is a simple but efficient library that provides BloCs class without headaches.

IMPORTANT: Dart2 is required to use this package.

Installation #

  • Add dash to your pubspec.yaml under the dependencies section:
dependencies:
  dash: ^latest_version
  • Add build_runner and dash_generator to your pubspec.yaml under the dev_dependencies section:
dev_dependencies:
  build_runner: ^1.1.3
  dash_generator: ^latest_version

Usage #

1 - Create a provider class that is going to gathering all BlocProvider annotation:

IMPORTANT: Do not forget to add: part 'provider.g.dart';.

import 'package:dash/dash.dart';

part 'provider.g.dart';

@BlocProvider.factory(MySampleBloc)
@BlocProvider.factory(MyOtherBloc)
abstract class Provider {}

2 - Extends all your bloc class from Bloc. It will allow you to override disposable and dispose method.

IMPORTANT: In order to cache bloc class it must has an unique ID that is represented by a static string property named as key. Also an instance() function that returns the instance of the bloc class as show bellow is necessary.

class MySampleBloc extends Bloc {
  static final String key = 'MySampleBloc-uid';

  @override
  bool disposable() {
    return true;
  }

  @override
  dispose() {
    //close all streams
  }

  static Bloc instance() {
    return MySampleBloc();
  }
}

class MyOtherBloc extends Bloc {
  static final String key = 'MyOtherBloc-uid';

  @override
  bool disposable() {
    return true;
  }

  @override
  dispose() {
    //close all streams
  }

  static Bloc instance() {
    return MyOtherBloc();
  }
}

3 - Run build_runner, it will generate the provider.g.dart class that you added as part on your provider class.

On project directory run on terminal:

pub run build_runner build

For flutter is:

flutter packages pub run build_runner build

Note: If you encounter a conflict error, please add the --delete-conflicting-outputs argument to your command:

flutter packages pub run build_runner build --delete-conflicting-outputs

4 - Finally you can get your bloc class instance from wherever you want, example:

@override
  Widget build(BuildContext context) {
    final _bloc = $Provider.of<MyOtherBloc>();

    return Container();
  }

Changelog #

Please see the Changelog page to know what's recently changed.

[0.4.0] - February second 2019.

  • Changed the way of how blocs are disposed

example/dash_example.dart

import 'package:dash/dash.dart';

class Main {
  void anyMethod() {
    BlocSample _bloc = Provider.of<BlocSample>();
  }
}

class Provider {
  static T of<T extends Bloc>([List<String> keepBlocs = const []]) {
    switch (T) {
      case BlocSample:
        {
          return BlocCache.getBlocInstance(
              BlocSample.key, () => BlocSample.instance());
        }
    }
    return null;
  }
}

class BlocSample extends Bloc {
  String test = 'BlocSample';
  static final String key = 'BlocSample';

  static BlocSample instance() => BlocSample();

  @override
  bool disposable() {
    return false;
  }

  @override
  dispose() {
    //close streams
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  dash: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:dash/dash.dart';
  
Version Uploaded Documentation Archive
0.4.0 Feb 8, 2019 Go to the documentation of dash 0.4.0 Download dash 0.4.0 archive
0.3.0 Feb 3, 2019 Go to the documentation of dash 0.3.0 Download dash 0.3.0 archive
0.2.0 Feb 3, 2019 Go to the documentation of dash 0.2.0 Download dash 0.2.0 archive
0.1.0 Jan 28, 2019 Go to the documentation of dash 0.1.0 Download dash 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
51
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]
75
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.13+1

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dash/dash.dart.

Health issues and suggestions

Document public APIs. (-1 points)

17 out of 17 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.

Format lib/dash.dart.

Run dartfmt to format lib/dash.dart.

Format lib/src/annotations.dart.

Run dartfmt to format lib/src/annotations.dart.

Format lib/src/bloc.dart.

Run dartfmt to format lib/src/bloc.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.0.0