sealed_unions_generator 0.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new53

sealed_unions_generator #

Sealed Unions Generator uses basic annotations to generate the boiler plate for your state models.

How to use #

pubspec.yaml of your plugin

dependencies:
  sealed_unions_annotations: ^0.0.1
    
    
dev_dependencies:
  build_runner: ^1.6.5
  sealed_unions_generator: ^0.0.1

You write this

import 'package:sealed_unions_annotations/sealed_unions_annotations.dart';
import 'package:sealed_unions/sealed_unions.dart';

part 'weather_model.g.dart';
@Seal('WeatherState')
abstract class WeatherModel {
  @Sealed()
  void initial();
  @Sealed()
  void loading();
  @Sealed()
  void loaded(int temperature);

}

You run the command

flutter pub run build_runner build      

and the project writes this:

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'weather_model.dart';

// **************************************************************************
// SealedUnionsGenerator
// **************************************************************************

class WeatherState extends Union3Impl<WeatherStateInitial, WeatherStateLoading,
    WeatherStateLoaded> {
  static final Triplet<WeatherStateInitial, WeatherStateLoading,
          WeatherStateLoaded> _factory =
      const Triplet<WeatherStateInitial, WeatherStateLoading,
          WeatherStateLoaded>();

  WeatherState._(
      Union3<WeatherStateInitial, WeatherStateLoading, WeatherStateLoaded>
          union)
      : super(union);

  factory WeatherState.initial() =>
      WeatherState._(_factory.first(WeatherStateInitial()));

  factory WeatherState.loading() =>
      WeatherState._(_factory.second(WeatherStateLoading()));

  factory WeatherState.loaded(int temperature) =>
      WeatherState._(_factory.third(WeatherStateLoaded(temperature)));
}

class WeatherStateInitial {
  WeatherStateInitial();
}

class WeatherStateLoading {
  WeatherStateLoading();
}

class WeatherStateLoaded {
  final int temperature;

  WeatherStateLoaded(this.temperature);
}


The command will create WeatherState class and that class will have factories to control the state. You won't access your class WeatherModel, but the generated one to control the state. This is a downside of this project and I have not found a solution for this.

Use WeatherState.initial(), WeatherState.loading() and WeatherState.loaded(1) directly as there is no point to hide it behind WeatherState since you will need to use WeatherState.join(A,B,C).

[0.0.2]

  • Made generated classes public.
  • Added example.

[0.0.1]

  • Initial release.

example/README.md

example #

A new Flutter application.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  sealed_unions_generator: ^0.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:sealed_unions_generator/sealed_unions_generator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
53
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: other

Primary library: package:sealed_unions_generator/sealed_unions_generator.dart with components: io, build, mirrors.

Health suggestions

Fix lib/src/sealed_unions_generator.dart. (-0.50 points)

Analysis of lib/src/sealed_unions_generator.dart reported 1 hint:

line 114 col 22: Don't explicitly initialize variables to null.

Format lib/sealed_unions_generator.dart.

Run dartfmt to format lib/sealed_unions_generator.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (analyzer).

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
analyzer >=0.37.1 <0.38.2 0.38.1 0.38.5
build ^1.1.5 1.2.0
meta ^1.1.6 1.1.7
sealed_unions_annotations ^0.0.2 0.0.2
source_gen ^0.9.4 0.9.4+5
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.2.10 1.3.1
front_end 0.1.23 0.1.27
glob 1.1.7
html 0.14.0+3
kernel 0.3.23 0.3.27
logging 0.11.3+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_runner ^1.6.5
build_test ^0.10.8
test ^1.6.5