Git Product home page Git Product logo

dart_dataclass's Introduction

Hi there!

Checkout apps I've created with others under my portfolio.

dart_dataclass's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dart_dataclass's Issues

Issue with collections dependency while running GitHub Actions

Because every version of flutter_test from sdk depends on collection 1.15.0-nullsafety and dataclass 0.3.0+1 depends on collection >=1.14.0 <1.15.0, flutter_test from sdk is incompatible with dataclass 0.3.0+1.

And because no versions of dataclass match >0.3.0+1 <0.4.0, flutter_test from sdk is incompatible with dataclass ^0.3.0+1.

Change to mixins insthead of abstract classes

Hello,

I've found that in some situations it is needed to inherit another abstract class. Therefore the generated base class is not always appropriate. Instead, do generate a mixing.

Cheers,

Generator should not use getter fields for generated methods

Example

@dataClass
class PaginationMeta extends _$PaginationMeta {
  final int page;
  final int total;
  final int perPage;

  bool get hasMorePages => perPage * page < total;

  PaginationMeta({this.page, this.total, this.perPage});
}

Generated code

abstract class _$PaginationMeta {
  const _$PaginationMeta();

  int get page;
  int get total;
  int get perPage;
  bool get hasMorePages;
  bool operator ==(other) {
    if (identical(this, other)) return true;
    if (other is! PaginationMeta) return false;

    return true &&
        this.page == other.page &&
        this.total == other.total &&
        this.perPage == other.perPage &&
        this.hasMorePages == other.hasMorePages;
  }

  int get hashCode {
    return mapPropsToHashCode([page, total, perPage, hasMorePages]);
  }

  String toString() {
    return 'PaginationMeta <\'page\': ${this.page},\'total\': ${this.total},\'perPage\': ${this.perPage},\'hasMorePages\': ${this.hasMorePages},>';
  }

  PaginationMeta copyWith(
      {int page, int total, int perPage, bool hasMorePages}) {
    return PaginationMeta(
      page: page ?? this.page,
      total: total ?? this.total,
      perPage: perPage ?? this.perPage,
      hasMorePages: hasMorePages ?? this.hasMorePages, // THIS SHOULD NOT BE USED
    );
  }
}

Allow static fields

Currently library fails if class has at any static fields (which should not affect data class at all).

For ex.

@dataClass
class Contact extends _$Contact {
  static const unknownName = '{empty}';

  final String name;
}

Such example throws an error:

[SEVERE] dataclass_generator:dataclass on lib/contact.dart:

@DataClass should have final fields only

Add a annotation to ignore features

It would be nice if one can ignore some features if needed. For instance, take the code bellow:

import 'package:flutter/material.dart';
import './passage.dart';

part 'search_result.g.dart';

@DataClass(withCopy: false)
@immutable
class SearchResult {
  final String query;
  final int page;

  @DataClassField(equal: false)
  final int totalHits;

  @DataClassIgnore
  final List<Passage> hits;

  SearchResult({this.query, this.page, this.totalHits, this.hits});
}

It represents a search query, if query and page are equals I don't need to check other fields to know it's the same value as other.

It would also be nice to ignore at class level, like copyWith.

How does it compare to built_value?

Hi.

The package looks useful and simple. I am wondering how it compares to built_value. Basically, I want to replace built_value with this package and the class properties be all final. This way I can have immutable classes with equals and copyWith. And with less code than with built_value.

Am I missing something? Are there any thing to consider? I suppose I have to continue using BuiltList instead of List right?

Thanks.

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.