dart_object_extension 0.1.1 copy "dart_object_extension: ^0.1.1" to clipboard
dart_object_extension: ^0.1.1 copied to clipboard

This plugin extends the functionality of the object class.

dart_object_extension #

pub

This plugin is a dart object extension plugin.

Features #

  • CopyWith (nullable available)

Setup #

Set the following in pubspec.yaml

dependencies:
  ...
  dart_object_extension: latest

dev_dependencies:
  ...
  build_runner: ^2.1.11
  dart_object_extension_gen: latest

Annotation Example #

CopyWith #

for example, create a stduent.dart file.

import 'package:dart_object_extension/dart_object_extension.dart';

part 'person.g.dart';

@CopyWith()
class Person {
  final int id;
  final String name;
  final int? age;

  const Person({
    required this.id,
    required this.name,
    this.age,
  });
}

Run code generation

flutter pub run build_runner build

copywith extension uses Functional parameters. A null check is also possible.

  • Basic Example
const person = Person(id: 0, name: 'Jin');
final personOther = person.copyWith(
  name: () => 'Sugar',
  age: () => 25,
);
  • Compile Error Example (name is not nullable)
const person = Person(id: 0, name: 'Jin');
final personOther = person.copyWith(
  name: () => null, // compile error
);
  • Compile Pass Example (age is nullable)
const person = Person(id: 0, name: 'Jin');
final personOther = person.copyWith(
  age: () => null, // compile pass
);
0
likes
120
pub points
42%
popularity

Publisher

unverified uploader

This plugin extends the functionality of the object class.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

meta

More

Packages that depend on dart_object_extension