Coder Social home page Coder Social logo

dash's Introduction

Dash

Logo

Dash is a simple but efficient library that helps provide BloCs 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 will gather BlocProvider annotation:

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

import 'package:dash/dash.dart';

part 'provider.g.dart';

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

2 - Extend BLoCs from Bloc. It will allow you to override dispose method.

IMPORTANT: All blocs must have an instance() function that returns the instance of the bloc as below.

class MySampleBloc extends Bloc {

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

  static Bloc instance() => MySampleBloc();
  
}

class MyOtherBloc extends Bloc {

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

  static Bloc instance() => 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 in terminal:

pub run build_runner build

For flutter:

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 instance from anywhere, for example:

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

    return Container();
  }

  @override
  void dispose() {
    $Provider.dispose<MyOtherBloc>();
    super.dispose();
  }

Changelog

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.