flutter_bloc_annotations 0.2.6

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

flutter_bloc_annotations

Usage

To import the annotations and Service abstract class add flutter_bloc_annotations to your pubspec.yaml.

dependencies:
  flutter_bloc_annotations: <latest_version>

Import Requirements

flutter_bloc_annotations uses InheritedWidget, StatefulWidget, State, Widget and BuildContext from package:flutter/material.dart. This needs to be imported as the generated part file cannot have import statements. Any services that are used also need to be imported.

Class Member Requirements

All the members of your BLoC class that have annotations must be public as the generated code uses them. Members without annotations can still be used in @BLoCMapper methods as the member is called and not copied to the output class. @BLoCValues initial data will not be copied to the BLoC class and will have no effect on the initial data.

Different Controllers

Using StreamController isn't required so rxdarts subjects such as BehaviourSubject can be used as shown in the example.

Output Classes

The output classes can be seen in the generated .bloc.dart file. Generally a BLoC, Provider and Disposer are created. The BLoC class defines the inputs and outputs of the bloc and calls your @BLoCMappers when somthing is added to the input streams and adds the output to the output streams. The BLoC class will also create, initialize and dispose of any services you require.

Services

Services are automatic inputs to a BLoC that are initialized when the bloc is created. This makes it easier to make database connections that automatically add to the BLoC while still being testable without creating a an entire BLoC to add to as they only require a Sink to add to.

Examples

// main.dart
import "dart:async";
import "package:flutter/material.dart";
import "package:flutter_bloc_annotations/flutter_bloc_annotations.dart";
import "service.dart";
part "main.bloc.dart";

@BLoC()
@BLoCService("TestService", "setCounter")
class _Test {
  @BLoCInput()
  StreamController<int> setCounter = StreamController<int>();

  @BLoCOutput()
  StreamController<int> counter = StreamController<int>();

  @BLoCValue("counter")
  int counterValue;

  @BLoCMapper("setCounter", "counter")
  Future<int> setCounterToCounter(int inputData) async => inputData;
}
// service.dart
import "package:flutter_bloc_annotations/flutter_bloc_annotations.dart";

class TestService extends InputService<int> {
  @override
  void init(Sink<int> sink) async {
    await Future.delayed(Duration(seconds: 10));
    sink.add(10);
  }

  @override
  void dispose() {}
}

More extensive examples can be found in the root example/ directory.

0.2.6

  • Add MapperService, AsyncMapperService, RequireMapperService and RequireAsyncMapperService

0.2.5

  • Currect trigger types to Future from void
  • Make mappers optionally async

0.2.4

  • Add TriggeredService

0.2.3

  • Allow mappers to return null to not add anything to the output

0.2.2

  • Added paramaters that can be passed to the BLoC and are accessible to BLoC services

0.2.1

  • Make requiring a service require the service type
  • Add BLoCService service that takes an entire BLoC instead of a Stream or Sink

0.2.0

  • Make mappers async

0.1.9

  • Make template value the only current value stored

0.1.8

  • Moved value updater before calling mappers
  • Updating latest values on template

0.1.7

  • OutputService automatic listener
  • OutputService automatic subscription disposer

0.1.6

  • Remove current data from mappers

0.1.5

  • Updated service documentation

0.1.4

  • Changed Service to InputService and added OutputService
  • Corrected name in README

0.1.3

  • Fix README discrepencies

0.1.2

  • Added documentation comments

0.1.1

  • Fix library name
  • Add example
  • Format code

0.1.0

  • Initial public release

example/example.dart

/// A full example is available a https://github.com/CallumIddon/flutter_bloc_generator/example

// main.dart
import "dart:async";
import "package:flutter/material.dart";
import "package:flutter_bloc_annotations/flutter_bloc_annotations.dart";
import "service.dart";
part "main.bloc.dart";

@BLoC()
@BLoCRequireInputService("TestService", "setCounter")
class _Test {
  @BLoCInput()
  StreamController<int> setCounter = StreamController<int>();

  @BLoCOutput()
  StreamController<int> counter = StreamController<int>();

  @BLoCValue("counter")
  int counterValue;

  @BLoCMapper("setCounter", "counter")
  int setCounterToCounter(int inputData, int currentData) => inputData;
}

// service.dart
import "package:flutter_bloc_annotations/flutter_bloc_annotations.dart";

class TestService extends InputService<int> {
  @override
  void init(Sink<int> sink) async {
    await Future.delayed(Duration(seconds: 10));
    sink.add(10);
  }

  @override
  void dispose() {}
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_bloc_annotations: ^0.2.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support 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:flutter_bloc_annotations/flutter_bloc_annotations.dart';
  
Version Uploaded Documentation Archive
0.2.6 Nov 21, 2018 Go to the documentation of flutter_bloc_annotations 0.2.6 Download flutter_bloc_annotations 0.2.6 archive
0.2.5 Nov 11, 2018 Go to the documentation of flutter_bloc_annotations 0.2.5 Download flutter_bloc_annotations 0.2.5 archive
0.2.4 Nov 10, 2018 Go to the documentation of flutter_bloc_annotations 0.2.4 Download flutter_bloc_annotations 0.2.4 archive
0.2.3 Nov 9, 2018 Go to the documentation of flutter_bloc_annotations 0.2.3 Download flutter_bloc_annotations 0.2.3 archive
0.2.2 Nov 9, 2018 Go to the documentation of flutter_bloc_annotations 0.2.2 Download flutter_bloc_annotations 0.2.2 archive
0.2.1 Nov 9, 2018 Go to the documentation of flutter_bloc_annotations 0.2.1 Download flutter_bloc_annotations 0.2.1 archive
0.2.0 Nov 7, 2018 Go to the documentation of flutter_bloc_annotations 0.2.0 Download flutter_bloc_annotations 0.2.0 archive
0.1.9 Nov 7, 2018 Go to the documentation of flutter_bloc_annotations 0.1.9 Download flutter_bloc_annotations 0.1.9 archive
0.1.8 Nov 7, 2018 Go to the documentation of flutter_bloc_annotations 0.1.8 Download flutter_bloc_annotations 0.1.8 archive
0.1.7 Nov 7, 2018 Go to the documentation of flutter_bloc_annotations 0.1.7 Download flutter_bloc_annotations 0.1.7 archive

All 17 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
53
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]
76
Learn more about scoring.

We analyzed this package on Nov 21, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
meta ^1.1.6 1.1.6
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8