Git Product home page Git Product logo

data_class's Introduction

Felix's Github Stats Top Langs

Hi there 👋

I'm a software engineer at Shorebird in Chicago, IL 🌆

  • 🧱 I’m currently working on BrickHub
  • 🔭 I maintain the bloc library
  • ☕ I’m learning how to make latte art
  • 🧑‍💻 I’m looking to collaborate on open source projects
  • 💬 Ask me about Flutter and Dart.
  • 😄 Pronouns: he/him/his
  • ⚡ Fun fact: I have a pet bunny named Coco 🐰

Open Source Projects

Bloc Bloc.js Equatable Mason Mocktail FlowBuilder

data_class's People

Contributors

felangel avatar pedromassango avatar

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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

data_class's Issues

feat: A macros for generating fake data

Description
When developing, sometimes you have to fill models with data with your own hands when there is no other data or use third-party packages

Desired Solution
Give the opportunity to add an annotation to generate fake data

Alternatives Considered
https://pub.dev/packages/faker

Yes, it sounds so easy, in fact, you have to take a lot into account, like the length of the strings that you want to generate, etc.) But is it possible to do this with anatations on top of class properties?) If this feature is not suitable for this plugin, can we open a new repo as a new plugin?

feat: improve equality comparisons

Currently just using deep collection equality which isn't very performant and can be improved significantly. Also would be nice to share code with package:equatable here.

test: add unit tests

This package is in the experimentation phase but eventually if it seems promising the package should be fully unit tested.

fix: analyser throws errors but runs fine with example code

Description
When experimenting with the example in the README, both VSCode and IntelliJ editors throw syntax errors on my machines. The errors are not affected by the contents of the analysis_options.yaml file. It seems as though the macro is not being registered. Macros from other libraries such as json work fine.

Steps To Reproduce

  1. Copy example from README and place into new dart project.
  2. Add dependency for data_class and update analysis_options.yaml
  3. Run dart pub get
  4. See error in editor
  5. Code runs fine in terminal

Expected Behavior
No syntax errors in editor. Option to view augmented code.

Screenshots
Errors in VSCode
Screenshot 2024-06-25 at 7 31 33 PM

Screenshot 2024-06-25 at 7 31 53 PM

Output
Screenshot 2024-06-25 at 7 45 39 PM

Additional Context
Flutter version
Screenshot 2024-06-25 at 7 39 18 PM

Pubspec
Screenshot 2024-06-25 at 7 41 15 PM

Analysis Options
Screenshot 2024-06-25 at 7 46 33 PM

feat: some version of serialisation

Description

Data classes are usually converted to a more generic form (string or map) when interacting with external libraries. I'm not sure of the scope of this library, but a feature to serialise the data classes would be great. It does not have to be a complete solution to compete with other emerging libraries, but complete enough to coexist with existing data_class constructors and toString methods.

Desired Solution

A feature to serialise the attributes of a data class.

import 'package:data_class/data_class.dart';

@Data()
class Person {
  final String name;
}

void main() {
  // 🪨 Create a const instance with required, name parameters.
  const dash = Person(name: 'Dash');

  // Serialise
  print(dash.toMap()); // {name: Dash} OR
  print(dash.toJson(); // {"name": "Dash"}

  // Deserialise 
  final sam = Person.fromMap({'name': 'Sam'}); // OR
  final john = Person.fromJson('{"name": "John"}');
}

Alternatives Considered

Using the json package; however, it currently has limitations on enums, dynamic values, date time etc.

feat: simpler `copyWith` syntax

Description

It'd be nice to revert back to the original copyWith API (no lambdas) but be able to maintain the ability to copyWith null values.

Desired API

@Data()
class Person {
  final String name;
  final String? nickname;
}

void main() {
  const dash = Person(name: 'Dash', nickname: 'Dashy');
  print(dash.copyWith()); // Person(name: Dash, nickname: Dashy)
  print(dash.copyWith(name: 'Sparky')); // Person(name: Sparky, nickname: Dashy)
  print(dash.copyWith(nickname: null)); // Person(name: Dash, nickname: null)
}

Additional Context

#3 (comment)

Update data_class package to support the latest macros version

Description

Currently, the data_class package is not compatible with the latest version of the macros package (0.1.2-main.0). This is causing issues with code generation, as certain APIs have been renamed or removed in the latest macros version.

Steps to Reproduce:

  1. Attempt to use the data_class package with macros version 0.1.2-main.0.
  2. Observe errors related to missing or renamed APIs.

Desired Solution

Always be with latest Version

Additional Context

  • The macros package is currently under development and is considered an experimental feature.
  • Further API changes and updates are expected in future versions of the macros package.
  • It's recommended to periodically check for updates and changes in the macros package to ensure compatibility with the data_class package. , As most of Users were using the Master Branch of flutter to just check Macros

feat: @Initialable Static .initial() function & .isInitial property

Description

It would be really handy if a static initial(), function could be created for every property.
This would be in the line of immutable objects and the copy with function.

It would take the 'initial' values of each primary type/class in dart. And if there is a custom type, check if that has the Data Class annotation on it to see if it has a .initial function.

Example:

@Initialable
class TestClass extends Equatable {
  final String name;
  final DateTime dateOfBirth;
  final double? age;
  final List<int> chains;

  const TestClass({
    required this.dateOfBirth,
    required this.name,
    required this.age,
    required this.chains,
  });

  bool get isInitial => this == TestClass.initial();

  factory TestClass.initial() {
    return TestClass(
      age: null,
      chains: List.empty(growable: true),
      dateOfBirth: DateTime.fromMillisecondsSinceEpoch(0),
      name: '',
    );
  }
}

This is useful in immutable objects.

fix: data_class Macro Fails to Generate Code

Description
data_class macro does not work.

Steps To Reproduce

  1. Install FVM

  2. Install flutter
    Run fvm install 3.23.0-0.1.pre

  3. Enable flutter global version
    Run fvm global 3.23.0-0.1.pre

  4. Create flutter app
    Run fvm flutter create poc_data_class

  5. Add config to file analysis_options.yaml

analyzer:
  enable-experiment:
    - macros
  1. Add package "data_class"
    Run fvm flutter add data_class

  2. Add package "json" (to proof macro is work)
    Run fvm flutter add json

  3. Add file temp.dart to /lib

import 'package:data_class/data_class.dart';
import 'package:json/json.dart';

@JsonCodable()
class Location {
  final double latitude;
  final double longitude;
}

@Data()
class Person {
  final String name;
}

void test() {
  final location = Location.fromJson({});

  const dash = Person(name: 'Dash');
  final sparky = dash.copyWith(name: 'Sparky');
}

Expected Behavior
Constructor and copyWith functions should work.

Actual Behavior
Error when create Person and use copyWith.

Screenshots
lib/temp.dart
Screenshot 2567-07-01 at 13 00 34

pubspec.yaml
Screenshot 2567-07-01 at 12 44 04

Additional Context
fvm flutter --version

Flutter 3.23.0-14.0.pre.76 • channel master • https://github.com/flutter/flutter.git
Framework • revision 1c9c375e4e (18 hours ago) • 2024-06-30 07:43:26 -0400
Engine • revision 0d93da7e2f
Tools • Dart 3.5.0 (build 3.5.0-318.0.dev) • DevTools 2.37.0

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.