meta_types 0.1.0

  • Example
  • Installing
  • Versions
  • new73


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

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


  • 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 packages get

Alternatively, your editor might support pub get or 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:meta_types/meta_types.dart';
Version Uploaded Documentation Archive
0.1.0 Aug 7, 2018 Go to the documentation of meta_types 0.1.0 Download meta_types 0.1.0 archive
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 Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:meta_types/meta_types.dart.

Issues and suggestions

Homepage does not exists.

We were unable to access at the time of the analysis.

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2-0-0-dev <3.0.0
meta ^1.0.0 1.1.6
Dev dependencies
build_runner ^0.9.0