dart_object_extension 0.2.0 copy "dart_object_extension: ^0.2.0" to clipboard
dart_object_extension: ^0.2.0 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
150
points
85
downloads

Publisher

unverified uploader

Weekly Downloads

This plugin extends the functionality of the object class.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on dart_object_extension