param 0.0.1 copy "param: ^0.0.1" to clipboard
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
19%
popularity

Publisher

verified publisherbalanci.ng

Simplifies changing/nullifying parameters for copyWith methods.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on param