single_bloc_base 1.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

single_bloc_base #

extra_pedantic on pub.dev Travis CI Codecov License Pub.dev Github Stars Twitter Follow GitHub Follow

Platform agnostic Bloc interfaces + HookBloc for Dart and Flutter

Provides interfaces for:

  • Disposable Blocs:
class ExampleBloc implements BlocBase {
  const ExampleBloc();

  @override
  Future<void> dispose() async {
  }
}
  • Initializable Objects:
class ExampleInit implements InitBase {
  const ExampleInit();

  @override
  Future<void> init() async {
  }
}
  • Initializable Blocs:
class ExampleBlocWithInit implements InitBloc {
  const ExampleBlocWithInit();

  @override
  Future<void> dispose() async {
  }

  @override
  Future<void> init() async {
  }
}
  • Bagged Initializable Blocs
class ExampleBaggedBloc extends BaggedInitBloc {
  ExampleBaggedBloc(Iterable<BlocBase> blocs,
      Iterable<InitializableBlocBase> initializableBlocs) {
    blocs.forEach(bagBloc);
    initializableBlocs.forEach(bagState);
    disposeLater(() => print("dispose me later"));
    initLater(() => print("init me later"));
  }
}
  • Hook Blocs that give you the ability to schedule objects for disposal in one line during their initialization:
class ExampleHookBloc extends HookBloc {
  final MyOtherBloc otherBloc = HookBloc.disposeBloc(MyOtherBloc());
}

class MyOtherBloc extends BlocBase {
  MyOtherBloc() {}

  @override
  Future<void> dispose() async {
    print("MyOtherBloc dispose");
  }
}

1.0.0+1 #

  • loosened meta constraint

1.0.0 #

  • Initial version, created by Stagehand

example/main.dart

import 'package:single_bloc_base/single_bloc_base.dart';

// ignore_for_file: unused_local_variable
Future<void> main() async {
  const simpleBloc = ExampleBloc();
  await simpleBloc.dispose();

  const simpleInit = ExampleInit();
  await simpleInit.init();

  const initBloc = ExampleBlocWithInit();
  await initBloc.init();
  await initBloc.dispose();

  final hookBloc = ExampleHookBloc();
  await hookBloc.dispose();

  final hookBloc2 = ExampleHookBloc();
  await hookBloc2.dispose();

  final baggedBloc = ExampleBaggedBloc(
    [const ExampleBloc(), ExampleHookBloc()],
    [const ExampleBlocWithInit()],
  );
  await baggedBloc.init();
  await baggedBloc.dispose();
}

class ExampleBloc implements BlocBase {
  const ExampleBloc();

  @override
  Future<void> dispose() async {
    print("ExampleBloc dispose");
  }
}

class ExampleInit implements InitBase {
  const ExampleInit();

  @override
  Future<void> init() async {
    print("ExampleInit dispose");
  }
}

class ExampleBlocWithInit implements InitBloc {
  const ExampleBlocWithInit();

  @override
  Future<void> dispose() async {
    print("ExampleBlocWithInit dispose");
  }

  @override
  Future<void> init() async {
    print("ExampleBlocWithInit init");
  }
}

class ExampleHookBloc extends HookBloc {
  final MyOtherBloc otherBloc = HookBloc.disposeBloc(MyOtherBloc());
}

class MyOtherBloc extends BlocBase {
  MyOtherBloc() {}

  @override
  Future<void> dispose() async {
    print("MyOtherBloc dispose");
  }
}

class ExampleBaggedBloc extends BaggedInitBloc {
  ExampleBaggedBloc(
      Iterable<BlocBase> blocs, Iterable<InitBloc> initializableBlocs) {
    blocs.forEach(bagBloc);
    initializableBlocs.forEach(bagState);
    disposeLater(() => print("dispose me later"));
    initLater(() => print("init me later"));
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  single_bloc_base: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:single_bloc_base/single_bloc_base.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
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]
67
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.4 <3.0.0
meta ^1.0.0 1.1.8
Dev dependencies
extra_pedantic ^1.1.1+2
test ^1.5.0
test_coverage ^0.2.0