Skip to content

Introducing copyUsing as null-safe alternative to copyWith

Latest
Compare
Choose a tag to compare
@spkersten spkersten released this 03 Jul 14:44
· 16 commits to master since this release

copyUsing

copyWith uses null to indicate that a field should have the same value in the copy as in the original. So it is not possible to set a nullable field to null. With copyUsing this is now possible:

@FunctionalData()
class Foo {
  const Foo(this.nullableField, this.otherField);

  final String? nullableField;
  final int otherField;
}

final copy = foo.copyUsing((change) =>
  change
    ..nullableField = null
    ..otherField = 7);
);

positional constructor parameters

The constructor used by functional_data can now have positional arguments (in addition to named ones):

@FunctionalData()
class Bar {
  const Bar(this.positional, {required this.named});

  final int positional;
  final int named;
}