nullable_absent 1.0.1 copy "nullable_absent: ^1.0.1" to clipboard
nullable_absent: ^1.0.1 copied to clipboard

Absent value for nullable field

example/nullable_absent_example.dart

import 'package:nullable_absent/nullable_absent.dart';

void main() {
  final data = MyData(id: "id", name: "name");
  print("data: $data");
  final dataWithNewName = data.copyWith(name: NullableAbsent("new_name"));
  print("dataWithNewName: $dataWithNewName");
  final dataWithNullName = data.copyWith(name: NullableAbsent(null));
  print("dataWithNullName: $dataWithNullName");
  final dataWithNewId = data.copyWith(id: "new_id");
  print("dataWithNewId: $dataWithNewId");
}

class MyData {
  final String id;
  final String? name;

  MyData({required this.id, required this.name});

  MyData copyWith({
    String? id,
    NullableAbsent<String> name = const NullableAbsent.absent(),
  }) {
    return MyData(
        id: id ?? this.id,
        name: name.replace(oldValue: this.name));
  }

  @override
  String toString() {
    return [id, name].toString();
  }
}
1
likes
0
points
516
downloads

Publisher

unverified uploader

Weekly Downloads

Absent value for nullable field

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on nullable_absent