undefinable 0.1.0 copy "undefinable: ^0.1.0" to clipboard
undefinable: ^0.1.0 copied to clipboard

Distinguish between defined and undefined values in Dart.

example/undefinable_example.dart

import 'package:undefinable/undefinable.dart';

void main() {
  final data = MyData(id: "id", name: "name");
  print("data: $data");
  final dataWithNewName = data.copyWith(name: Undefinable("new_name"));
  print("dataWithNewName: $dataWithNewName");
  final dataWithNullName = data.copyWith(name: Undefinable(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,
    Undefinable<String?> name = const Undefinable.undefined(),
  }) {
    return MyData(
        id: id ?? this.id, name: name.valueOr(this.name));
  }

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

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Distinguish between defined and undefined values in Dart.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on undefinable