meta_types 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

meta_types #

library used for defining union, enum, and data classes.

See examples for example usage. See dart_meta_types/ for more information.

0.1.0 #

  • initial annotations for annotating union, enum, and data classes
  • initial classes defined which all meta_types extend


import 'package:meta_types/meta_types.dart';

part 'example.g.dart';

// regular data class,
abstract class $ExampleDataClass {
  // fieldWithNoDefault is a field without a default value
  // the constructor will require a value be passed for this param
  int get fieldWithNoDefault;

  // fieldWithDefault uses a default value of 10 if
  // no other value is passed to the constructor
  int get fieldWithDefault => 10;

  // data class fields are not nullable, one must
  // use the Nullable class to represent nullable fields
  Nullable<int> get nullable;

  // computed fields memoize the result of the getter function
  int get computedField => fieldWithDefault + 5;

// ImplementorDataClass will implement $InterfaceDataClass
abstract class $ImplementorDataClass implements $InterfaceDataClass {
  int get foo;

// $InterfaceDataClass must only be implemented. It will not be constructable itself.
// It cannot be used in extends clauses, only implements clauses. Interfaces cannot
// have default values.
@DataClass(isInterface: true)
abstract class $InterfaceDataClass {
  String get bar;

// BaseDataClass will contain all fields from ParentDataClass and GrandparentDataClass
abstract class $BaseDataClass extends $ParentDataClass {
  int get foo;

// ParentDataClass will not be constructable since isAbstract is true
@DataClass(isAbstract: true)
abstract class $ParentDataClass extends $GrandparentDataClass {
  int get bar;

@DataClass(isAbstract: true)
abstract class $GrandparentDataClass {
  String get baz => 'baz';

// ExampleSealedClass will require one and only
// on of the following fields are set. A when function
// is also generated for easy switching. e.g.:
// sealedClassInstance.when<void>(
//   (intval) => print('int val is $intval'),
//   (strval) => print('str val is $strval'),
// );
abstract class $ExampleSealedClass {
  int get integer;
  String get string;

// enum class with int will using incrementing integers as values
// unless a nother value is specified

abstract class $ExampleEnumInteger {
  static int a; // 0
  static int b; // 1
  static int c = 1000; // 1000
  static int d; // 3

// enum class with strings will use field name as value
// unless a nother value is specified

abstract class $ExampleEnumString {
  static String a;
  static String b;
  static String c = 'custom';

// enum class with custom type.

abstract class $ProtocolState {
  static const Waiting waiting = Waiting();
  static const Talking talking = Talking();

abstract class Signal {
  ProtocolState get signal;

class Waiting implements Signal {
  const Waiting();
  ProtocolState get signal => ProtocolState.talking;

class Talking implements Signal {
  const Talking();
  ProtocolState get signal => ProtocolState.waiting;

// Binary tree is an example of an algebreic data type
// It is the combination of two unions

abstract class $BinaryTree<T> {
  T get leaf;
  $Branch<T> get branch;

abstract class $Branch<T> {
  T get val;
  $BinaryTree<T> get left;
  $BinaryTree<T> get right;

void preorderTraversal(BinaryTree<int> tree) => tree.when(
      leaf: (val) {
      branch: (b) {

Use this package as a library

1. Depend on it

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

  meta_types: ^0.1.0

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:meta_types/meta_types.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.4

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field was unreachable.

Package is getting outdated. (-45.21 points)

The package was last published 75 weeks ago.

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 Constraint Resolved Available
Direct dependencies
Dart SDK >=2-0-0-dev <3.0.0
meta ^1.0.0 1.1.8
Dev dependencies
build_runner ^0.9.0