Giter Club home page Giter Club logo

flutter_vnum's People

Contributors

amirkamali avatar jayvdb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flutter_vnum's Issues

Having troubled in installation.

import 'main.reflectable.dart';
import 'package:reflectable/reflectable.dart';
initializeReflectable();

Build.yaml:

targets:
  $default:
    builders:
      reflectable:
        generate_for:
          - lib/main.dart
          - test/**_widget_test.dart
        options:
          formatted: true

My project is not able to resolve this step.

build_runner confusion

Could you please clarify when I need to regenerate codes with

packages pub run build_runner build --delete-conflicting-outputs

as opposed to:

packages pub run build_runner build

dart pub get vnum fails

https://github.com/adsharma/py2many/pull/112/checks?check_run_id=2427684955

Because every version of vnum depends on flutter any from sdk which is forbidden, vnum is forbidden.
So, because tests depends on vnum any, version solving failed.

py2many is a transpiler. So we're sensitive to our CI runtimes and would like to minimize dependencies.
Specifically, would like to stick to the core language libraries instead of frameworks.

Thank you for building vnum! I couldn't get some of the python features to work with dart enums.

Needed for py2many/py2many#26

upgrade dep json_annotation to 4.0.0

need to upgrade to json_annotion 4.0.0 to switch to null safety

Because vnum 1.2.6 depends on json_annotation ^3.0.1 and no versions of vnum match >1.2.6 <2.0.0, vnum ^1.2.6 requires json_annotation ^3.0.1.

Can Vnum have multiple properties?

You've got an example:

String color(){
    if (value == CarType.sedan.value) {
      return "Green";
    }else if (value == CarType.suv.value) {
      return "Orange";
    }else if (value == CarType.truck.value) {
      return "Yellow";
    }
    return "Unknown";
  }

Is it possible to make color as a property of enum item and rewrite method as:

String color(){
  return this._color;
}

?

Will soon serialization / deserializiation work in this case?

Bad state: Reflectable has not been initialized.

during vnum deserialization I get this error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Bad state: Reflectable has not been initialized.
E/flutter (17762): Please make sure that the first action taken by your program
E/flutter (17762): in `main` is to call `initializeReflectable()`.
E/flutter (17762): #0      data (package:reflectable/src/reflectable_builder_based.dart:177:5)
E/flutter (17762): #1      data (package:reflectable/src/reflectable_builder_based.dart)
E/flutter (17762): #2      ReflectableImpl.reflectType (package:reflectable/src/reflectable_builder_based.dart:2544:26)
E/flutter (17762): #3      Vnum._fetchValue (package:vnum/vnum.dart:46:42)
E/flutter (17762): #4      new Vnum.fromValue (package:vnum/vnum.dart:40:12)

my code looks like

@VnumDefinition
class OrganizationType extends Vnum<String> {
  /// Constructors
  const OrganizationType.define(String fromValue) : super.define(fromValue);
  factory OrganizationType(String value) => Vnum.fromValue(value, OrganizationType);
  factory OrganizationType.fromJson(dynamic json) => OrganizationType(json);

  /// Cases
  static const OrganizationType customer = OrganizationType.define('customer');
  static const OrganizationType supplier = OrganizationType.define('supplier');

@override
  dynamic toJson() => value;
}

what is the problem? should I add initializeReflectable() ?

VNum and Freezed Compatibility

VNum is very compatible with json_seriliazable but there seems to be a problem when it comes to using Vnums in freezed classes. Freezed itself uses json_serilizable. For example:

userType.dart

@VnumDefinition
class UserType extends Vnum<String> {
  static const UserType superAdmin = UserType.define('super-admin');
  static const UserType admin = UserType.define('admin');
  static const UserType staff = UserType.define('staff');
  static const UserType student = UserType.define('student');

  const UserType.define(String fromValue) : super.define(fromValue);
  factory UserType(String value) => Vnum.fromValue(value,UserType);

  @override
  String toJson() => value;
  factory UserType.fromJson(String json) => UserType(json);
}

person.dart

import 'package:admin/models/userType.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'person.freezed.dart';
part 'person.g.dart';

@freezed
abstract class Person implements _$Person {
  factory Person(@JsonKey(name: 'userType') UserType userType, String name, String imageUrl, String thumbnail) = _Person;
  factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
}

Expected Behaviour
in person.g.dart there should be appropriate deserialisation for UserType

Actual Behaviour
person.g.dart

Map<String, dynamic> _$_$_PersonToJson(_$_Person instance) => <String, dynamic>{
      'userType': instance.userType,
      'name': instance.name,
      'imageUrl': instance.imageUrl,
      'thumbnail': instance.thumbnail,
    };

There is no proper deserialisation. To correctly deserialise you have to enter serialisation methods in @JsonKey annotation like this

@JsonKey(name: 'userType', fromJson: _userTypeFromJson,  toJson: _userTypeToJson) UserType userType

Null safety

$ dart pub upgrade --null-safety
null-safety compatible versions do not exist for:

  • vnum

Can this be addressed in one of the upcoming releases? Cc: @jayvdb

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.