nonconst<T> function

T nonconst<T>(
  1. T t
)

This function can be used to call a const constructor in such a way as to create a new instance rather than creating the common const instance.

class A {
  const A(this.i);
  final int? i;
}

void main () {
  // prevent prefer_const_constructors lint
  A(nonconst(null));

  // prevent prefer_const_declarations lint
  final int? $null = nonconst(null);
  final A a = nonconst(const A(null));
}

Implementation

T nonconst<T>(T t) => t;