Skip to content

Releases: spkersten/dart_functional_data

Introducing copyUsing as null-safe alternative to copyWith

03 Jul 14:44
Compare
Choose a tag to compare

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;
}