Annotation For Generating `copywith` Extensions Code Using `copy_with_extension_gen`

Defines the annotation used by copy_with_extension_gen to generate copyWith extensions.

For more information on how to use this package, see copy_with_extension_gen.

For more information on how this package works, see my blog article.

Use this package as a library

Depend on it

Run this command:

With Dart:

 $ dart pub add copy_with_extension

With Flutter:

 $ flutter pub add copy_with_extension

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):

dependencies:
  copy_with_extension: ^5.0.4

Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:copy_with_extension/copy_with_extension.dart';

example/example.dart

// ignore_for_file: unused_element

import 'package:copy_with_extension/copy_with_extension.dart';

/// Make sure the `part` is specified before running the builder.
/// part 'example.g.dart'; /// It should not be commented.

/// Lets you use it like this: `SimpleObject(id: "test").copyWith(id: "new values", intValue: 10).copyWithNull(intValue: true)`.
/// Or like this: `SimpleObject(id: "test").copyWith.id("new value")`.
@CopyWith(copyWithNull: true)
class SimpleObjectOldStyle {
  const SimpleObjectOldStyle({required this.id, this.intValue});

  final String id;
  final int? intValue;
}

/// Won't allow you to copy this object with a modified `id` field after object creation. It will always copy it from the original instance.
@CopyWith()
class SimpleObjectImmutableField {
  const SimpleObjectImmutableField({this.id, this.intValue});

  @CopyWithField(immutable: true)
  final String? id;
  final int? intValue;
}

/// Allows the use of a private constructor.
@CopyWith(constructor: "_")
class SimpleObjectPrivateConstructor {
  const SimpleObjectPrivateConstructor._({this.id, this.intValue});

  @CopyWithField(immutable: true)
  final String? id;
  final int? intValue;
}

Download details:

Author: oleksandrkirichenko.com

Source: https://github.com/numen31337/copy_with_extension

#flutter #android #ios

Annotation For Generating `copywith` Extensions Code Using `copy_with_extension_gen`
1.30 GEEK