value_t2_generator 1.0.21

  • Readme
  • Changelog
  • Example
  • Installing
  • 51

value_t2 #

Reasoning: #

specifying clases with copywith, equals, toString, required constructor fields and other standard features is actually a fair amount of work resulting in verbose code which makes it difficult to maintain and difficult to read. typeclasses (ish), value types (ish)

Solution: use value_t2 #

Basic features #

  • Equality
var bob1 = Person(age: 5, name: "bob");
var bob2 = Person(age: 5, name: "bob");

bob1 == bob2; //true
  • CopyWith (works on subclasses in same file)
var bob = Employee(age: 5, name: "bob", id: "123);
var bobby = bob.cwPerson(age: 6, name: "bobby");
var robert = bob.cwEmployee(age: 25, name: "robert", id: "123);

bobby is Employee; //true
robert is Employee; //true
  • ToString
var bob = Person(age: 5, name: "bob");
bob.toString() //age:5|name:"bob"
  • All fields are required, non nullable (through assert pattern) and final by default
var bob = Person(age: 5, name: "bob");
bob.age = 6; //error

//warning on missing parameter values
var bob = Person(age: 5);

//assert error if parameter is null
var bob = Person(age: 5, name: null);

More examples #

For more examples look at the Examples project in the github repository

Installation #

  • Import value_t2_annotation, value_t2_generator, quiver_hashcode and build_runner
dependencies:
  value_t2_annotation:
  quiver_hashcode:

dev_dependencies:
  build_runner:
  value_t2_generator

Usage #

  • Add three imports at top of each file
import 'package:meta/meta.dart';
import 'package:quiver_hashcode/hashcode.dart';
import 'package:value_t2_annotation/value_t2_annotation.dart';
  • Place a @ValueT2() annotation on every class
  • Prepend a dollar on the classname or two dollars for abstract classes when defining a class
  • Declare all classes as abstract
 abstract class $$MyAbstract class {

 abstract class $MyClass class {
  • when using the class don't use the dollar sign
 MyClass(a: "value")
  • simple definition
@ValueT2()
abstract class $Pet {
  String get type;
}
  • simple definition with implements
 @ValueT2()
 abstract class $Person {
   String get name;
 }

 @ValueT2()
 abstract class $Employe implements $Person {
   String get id;
 }
  • never use extends, only interfaces
@ValueT2()
abstract class $B implements $A {

More features #

  • Shorter and more simple syntax
@ValueT2()
abstract class $A {
  String get aValue;
}

//vs

class A {
  final String aValue;

  A({
    @required this.aValue,
  }) : assert(aValue != null);

  //toString, hasCode, ==
}
  • The properties of interfaces are implemented automatically (no need to specify them, just use implements)
@ValueT2()
abstract class $A {
  String get aValue;
}

@ValueT2()
abstract class $B implements $A {
  String get bValue;
}

var b = B(aValue: "A", bValue: "B");
  • Can override a property of a subclass
@ValueT2()
abstract class $A {
  Person get a;
}

@ValueT2()
abstract class $B implements $A {
  Employee get a;
}
  • Can specify generics
@ValueT2()
abstract class $$A<T1, T2> {
  T1 get x;
  T2 get y;
}

@ValueT2()
abstract class $B implements $$A<int, String> {
  String get z;
}

Limitations #

  • Custom getters are not supported
    • use functions instead
  • Methods on a class are not supported (use functions instead)
  • 'go to definition' takes you to the generated class
    • workaround1 - to get class info hover over the class
    • workaround2 - go to definition, then go to definition a second time to go to the dollar version of class
    • possible update in the future

Coming (if others want and are interested) #

See github issues

## 1.0.21
- update dependencies

## 1.0.20
- fix for analaysis by removing

## 1.0.19
- update dependencies

## 1.0.18
- update dependencies

## 1.0.17
- update dependencies

## 1.0.16
- classname at the beginning of my tostring method

## 1.0.15
- private constructors to allow default values

## 1.0.13
- bug ex20

## 1.0.13
- bug ex19

## 1.0.12
- bug ex18

## 1.0.11
- bumped up version from copywith following a bug

## 1.0.10
- Bug with non abstract classes with no fields

## 1.0.9
- bumped up version from copywith following a bug

## 1.0.8
- removed comments

## 1.0.7
- updated description

## 1.0.6
- health issues (pub.dev recommendations)

## 1.0.5
- bump annotation version

## 1.0.4
- bump annotation version

## 1.0.3
- toString
- equality check

## 1.0.2
- Changed the description because it was too long!

## 1.0.1
- Added examples and changes recommended by pub.

## 1.0.0
- First published version

example/example.dart

//see example project in github for more examples

//part 'example.g.dart';

//THE SIMPLEST OF EXAMPLES

//@ValueT2()
abstract class $Pet {
  String get type;
}

Use this package as a library

1. Depend on it

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


dependencies:
  value_t2_generator: ^1.0.21

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

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

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because:

  • package:value_t2_generator/value_t2_generator.dart that imports:
  • package:value_t2_generator/src/ValueT2Generator.dart that imports:
  • package:value_t2_generator/src/GeneratorForAnnotationX.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on ios

Because:

  • package:value_t2_generator/value_t2_generator.dart that imports:
  • package:value_t2_generator/src/ValueT2Generator.dart that imports:
  • package:value_t2_generator/src/GeneratorForAnnotationX.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on linux

Because:

  • package:value_t2_generator/value_t2_generator.dart that imports:
  • package:value_t2_generator/src/ValueT2Generator.dart that imports:
  • package:value_t2_generator/src/GeneratorForAnnotationX.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on macos

Because:

  • package:value_t2_generator/value_t2_generator.dart that imports:
  • package:value_t2_generator/src/ValueT2Generator.dart that imports:
  • package:value_t2_generator/src/GeneratorForAnnotationX.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on windows

Because:

  • package:value_t2_generator/value_t2_generator.dart that imports:
  • package:value_t2_generator/src/ValueT2Generator.dart that imports:
  • package:value_t2_generator/src/GeneratorForAnnotationX.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-web on web

Because:

  • package:value_t2_generator/value_t2_generator.dart that imports:
  • package:value_t2_generator/src/ValueT2Generator.dart that imports:
  • package:value_t2_generator/src/GeneratorForAnnotationX.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/utils.dart that imports:
  • package:build/build.dart that imports:
  • package:build/src/generate/run_post_process_builder.dart that imports:
  • package:build/src/builder/post_process_builder.dart that imports:
  • package:build/src/builder/builder.dart that imports:
  • package:build/src/builder/build_step.dart that imports:
  • package:build/src/asset/reader.dart that imports:
  • package:glob/glob.dart that imports:
  • package:glob/src/list_tree.dart that imports:
  • package:glob/src/io.dart that imports:
  • package:glob/src/io_export.dart that imports:
  • dart:io

Package not compatible with runtime js

Because:

  • package:value_t2_generator/value_t2_generator.dart that imports:
  • package:value_t2_generator/src/ValueT2Generator.dart that imports:
  • package:value_t2_generator/src/GeneratorForAnnotationX.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/utils.dart that imports:
  • package:build/build.dart that imports:
  • package:build/src/generate/run_post_process_builder.dart that imports:
  • package:build/src/builder/post_process_builder.dart that imports:
  • package:build/src/builder/builder.dart that imports:
  • package:build/src/builder/build_step.dart that imports:
  • package:build/src/asset/reader.dart that imports:
  • package:glob/glob.dart that imports:
  • package:glob/src/list_tree.dart that imports:
  • package:glob/src/io.dart that imports:
  • package:glob/src/io_export.dart that imports:
  • dart:io

Package not compatible with runtime native-aot

Because:

  • package:value_t2_generator/value_t2_generator.dart that imports:
  • package:value_t2_generator/src/ValueT2Generator.dart that imports:
  • package:value_t2_generator/src/GeneratorForAnnotationX.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Health issues and suggestions

Document public APIs. (-1 points)

2 out of 2 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/src/ValueT2Generator.dart.

Run dartfmt to format lib/src/ValueT2Generator.dart.

Format lib/src/adiHelpers.dart.

Run dartfmt to format lib/src/adiHelpers.dart.

Format lib/src/helpers.dart.

Run dartfmt to format lib/src/helpers.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.1 <3.0.0
analyzer >=0.39.5 <0.40.0 0.39.12
analyzer_models ^1.0.8 1.0.8
basic_utils ^2.4.8 2.5.5
build ^1.2.2 1.3.0
copy_with_e_generator ^1.0.7 1.0.8
dartx >=0.3.0 <0.7.0 0.4.2
source_gen ^0.9.5 0.9.6
value_t2_annotation ^1.0.4 1.0.4
Transitive dependencies
_fe_analyzer_shared 5.0.0
args 1.6.0
asn1lib 0.6.5
async 2.4.2
characters 1.0.0 1.1.0-nullsafety
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
copy_with_e_annotation 1.0.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
glob 1.2.0
html 0.14.0+3
http 0.12.1
http_parser 3.1.4
intl 0.16.1
js 0.6.2
json_annotation 3.0.1
logging 0.11.4
matcher 0.12.8
meta 1.2.2 1.3.0-nullsafety
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.2
pointycastle 1.0.2
pub_semver 1.4.4
quiver 2.1.3
source_span 1.7.0
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
time 1.3.0
tuple 1.0.3
typed_data 1.2.0 1.3.0-nullsafety
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_runner ^1.7.3
test ^1.11.1