param 0.0.1 icon indicating copy to clipboard operation
param: ^0.0.1 copied to clipboard

Simplifies changing/nullifying parameters for copyWith methods.

Simplifies changing/nullifying parameters for copyWith methods #

Examples #

Non-nullable parameter

import 'package:param/param.dart';

class Foo {
  final String value;

  Foo(this.value);

  Foo copyWith({Param<String>? value}) =>
      Foo(Param.apply(value, this.value));
}

You can:

  • Leave the value as-is by omitting the param (or passing null, it is the same).
  • Change the value with a param value of Param.set('new value')

Nullable parameter

class NullableFoo {
  final String? value;

  NullableFoo(this.value);

  NullableFoo copyWith({NullableParam<String?>? value}) =>
      NullableFoo(NullableParam.apply(value, this.value));
}

NullableParam is more flexible, you can:

  • Leave the value as-is by omitting the nullable param (or passing null, it is the same)
  • Change the value with a nullable param value of NullableParam.set('new value')
  • Set the value to null with a nullable param value of NullableParam.nullify()
0
likes
120
pub points
7%
popularity

Publisher

verified publisher iconbalanci.ng

Simplifies changing/nullifying parameters for copyWith methods.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

More

Packages that depend on param