dart_object_extension

Creator: coderz1093

Last updated:

0 purchases

dart_object_extension Image
dart_object_extension Images

Languages

Categories

Add to Cart

Description:

dart object extension

dart_object_extension #

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
copied to clipboard
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,
});
}

copied to clipboard
Run code generation
flutter pub run build_runner build
copied to clipboard
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,
);
copied to clipboard

Compile Error Example (name is not nullable)

const person = Person(id: 0, name: 'Jin');
final personOther = person.copyWith(
name: () => null, // compile error
);
copied to clipboard

Compile Pass Example (age is nullable)

const person = Person(id: 0, name: 'Jin');
final personOther = person.copyWith(
age: () => null, // compile pass
);
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.