toString top-level constant

ToString const toString

A short hand of ToString.

Allows you get rid of boring toString overriding, Ides does the same, but with this annotation hide the so long string to make your class more cleaner and if you change the class property you have no worries.

To do so, annotate your class with ToString and override toString method to make it point to the generated one as below.


@ToString()
class User {
  User(
    this.firstName,
    this.lastName,
    this.email,
    this.phone,
    this.dateOfBirth,
    this.country,
    this.city,
    this.postalCode,
  );

  final String firstName;
  final String lastName;
  final String email;
  final String phone;
  final DateTime dateOfBirth;
  final String country;
  final String city;
  final String postalCode;

  @override
  String toString() => $toString();
}

Implementation

const ToString toString = ToString();