value_t_generator 0.4.0

  • Readme
  • Changelog
  • Installing
  • 45

value_t #

Generates code to create a simple type with a copywith class and implements all the getter fields in any extended or implemented classes.

Advantages over coding it yourself #

Less code to write and less code to read back over too. Refactoring can be less because you don't need to change all the names in the copyWith definitions, constructors and where a class has been extended multiple times. A free toString implementation (I find this useful when comparing objects for tests)

Downsides over coding it yourself #

####Go to definition will take you to the generated class...two work arounds

  • Need to define a const constructor in the base type
  • Go to definition then on the $MyClass go to definition again...not much of an impedement
  • name the file the same as your class and instead of pressing f12 cmd + p and type the filename. This sounds like more work but because of the conciseness of your classes you can fit whole class heirarchies and related interfaces in a single file and still view all the definitions.
  • Also, the generated file will have the fields names so you can is it as a reference anyway

Renaming classes #

you must rename both your defition and the generated name $PersonClass and PersonClass. This one is more fiddly, press f2 on PersonClass and rename, then change the name of $PersonClass...this order will result in just two changes.


  var a = MarkingIncorrect("my answer", <String>["blah", "blah"], "fullWord");

  print("a is MarkingState:" + (a is Marking).toString());

  var d = a.copyWith(answer: "blah");


  Person a = WindowCleaner(pet: Pet(type: "cat"), name: "Bob", employeeId: 5, wetness: "wet");

  if (a is Employee) {
    print('I am an employee');

  if (a is Person) {
    print('I am a Person');

  var b = a.copyWith(name: "bobby");

  if (b is OftenWet) {
    print("windowCleaners are OftenWet");

When defining your class put a dollar infront of the name and make it abstract #

abstract class $MyClass {

When defining the fields make them non-final getters #

    String get name;

When using your class in code remove the dollar #

var a = MyClass("Adriaaan");

See example folder for usage #

Inspirations and alternatives #

built_value and meta_types

0.4.0 #

  • allow constants (so that we can allow constant default values)
  • override toString

0.3.0 #

  • removed the null checks if there is a default on a field
  • allow abstract classes

0.1.0 #

  • First published version, supports extends and implements

Use this package as a library

1. Depend on it

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

  value_t_generator: ^0.4.0

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_t_generator/value_t_generator.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 Nov 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21


Detected platforms: other

Primary library: package:value_t_generator/value_t_generator.dart with components: io, build, 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.

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

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

line 5 col 7: Use contains instead of indexOf

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

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

line 61 col 19: Use isNotEmpty instead of length

Format lib/src/elementSuperTypeToString.dart.

Run dartfmt to format lib/src/elementSuperTypeToString.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).

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and value_t_generator.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
analyzer >=0.35.4 <0.36.0 0.35.4 0.39.1
build ^1.1.1 1.2.2
collection ^1.14.11 1.14.12
quiver ^2.0.1 2.1.2+1
source_gen ^0.9.4+1 0.9.4+4 0.9.4+6
value_t_annotation ^0.4.0 0.4.0
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
convert 2.1.1
crypto 2.1.3
dart_style 1.2.4 1.3.3
front_end 0.1.14 0.1.29
glob 1.2.0
js 0.6.1+1
kernel 0.3.14 0.3.29
logging 0.11.3+2
matcher 0.12.6
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+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
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0
Dev dependencies
build_runner ^1.0.0
test ^1.0.0