Skip to content

nkming2/dart-to-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

to-string

Generate toString() for classes

Usage

@toString
class MyClass {
  @override
  String toString() => _$toString();

  final a = 0;
  final b = 0;
}
// MyClass {a: 0, b:0}

Ignoring a field:

@toString
class MyClass {
  @override
  String toString() => _$toString();

  final a = 0;
  @ignore
  final b = 0;
}
// MyClass {a: 0}

Formatting a field:

@toString
class MyClass {
  @override
  String toString() => _$toString();

  final a = 0;
  @Format(r"${$?.toStringAsFixed(1)}")
  final double b = 1.234;
}
// MyClass {a: 0, b:1.2}

For more details, checkout the example dir.

Packages

No packages published

Languages