Code Monkey home page Code Monkey logo

autoequal's Introduction

Pub Package

Provides Dart Build System builder for generating List<Object?> _autoequalProps private extensions for classes annotated with autoequal.

Usage

In your pubspec.yaml file:

  • Add to dependencies section autoequal: ^0.2.0
  • Add to dev_dependencies section autoequal_gen: ^0.2.0
  • Add to dev_dependencies section build_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

Annotate your class with @autoequal annotation:

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';.

Launch code generation:

flutter pub run build_runner build

The extension will be generated:

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'some_class.dart';

// **************************************************************************
// AutoequalGenerator
// **************************************************************************

extension _$SomeClassAutoequal on SomeClass {
  List<Object> get _autoequalProps => [id];
}

Additional features

Autoequal mixin

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});
}

Ignore field

The autoequal will exclude any field annotated with @ignoreAutoequal.

@ignoreAutoequal
final int random;

autoequal's People

Contributors

sunnydaydev avatar xioshock avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.