Provides Dart Build System builder for generating List<Object?> _autoequalProps
private extensions for classes annotated with autoequal.
- Add to
dependencies
sectionautoequal: ^0.2.0
- Add to
dev_dependencies
sectionautoequal_gen: ^0.2.0
- Add to
dev_dependencies
sectionbuild_runner: ^1.11.5
- Set
environment
to at least Dart 2.12.0 version like so:">=2.12.0 <3.0.0"
Your pubspec.yaml
should look like so:
name: project_name
description: project description
version: 1.0.0
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
...
autoequal: ^0.2.0
dev_dependencies:
...
build_runner: ^1.11.5
autoequal_gen: ^0.2.0
import 'package:autoequal/autoequal.dart';
import 'package:equatable/equatable.dart';
part 'some_class.g.dart';
@autoequal
class SomeClass extends Equatable {
final String id;
SomeClass({this.id, this.random});
@override
List<Object?> get props => _autoequalProps; //_autoequalProps will be generated
}
Make sure that you set the part file as in the example above part 'your_file_name.g.dart';
.
flutter pub run build_runner build
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'some_class.dart';
// **************************************************************************
// AutoequalGenerator
// **************************************************************************
extension _$SomeClassAutoequal on SomeClass {
List<Object> get _autoequalProps => [id];
}
The @autoequalMixin
or @Autoequal(mixin: true)
will additionally generate a mixin class.
mixin _$SomeClassAutoequalMixin on Equatable {
@override
List<Object?> get props => _$SomeClassAutoequal(this)._autoequalProps;
}
To use it just add it to your class:
@autoequalMixin
class SomeClass extends Equatable with _$SomeClassAutoequalMixin {
final String id;
SomeClass({this.id});
}
The autoequal
will exclude any field annotated with @ignoreAutoequal
.
@ignoreAutoequal
final int random;