to_string 0.1.0
to_string: ^0.1.0 copied to clipboard

outdated

A tools for generating toString method for class, based on build_runner

Pub Package

A tools for generating toString method for class, based on build_runner.

Installation #

Add dependencies in your pubspec.yaml:

dependencies:
  to_string: ^0.0.1

dev_dependencies:
  to_string_generator: ^0.0.1
  build_runner: ^1.7.1

Usage #

In class you want toString() method:

  • Annotate the class with ToString()
  • Override the toString method.
/// cat.dart
import 'package:to_string/to_string.dart';

part 'cat.g.dart';

@ToString()
class Cat {
  Cat(this.color, this.weight);
  
  String color;
  double weight;
  
  @override
  String toString() {
    // [_$CatToString] is generated at `cat.g.dart`
    return _$CatToString(this);
  }
}

Use build_runner

In flutter

flutter packages pub run build_runner build

In dart

pub run build_runner build

Then:

void main() {
  // result: Cat2{color: black, weight: 1.12}
  print(Cat("black", 1.12));
}

Features and bugs #

Please file feature requests and bugs at the Github Issue Tracker.

Github Issue tracker: https://github.com/lvsecoto/to_string/issues

9
likes
0
pub points
76%
popularity

A tools for generating toString method for class, based on build_runner

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on to_string