AmirKamali / Flutter_Vnum

This class library enables to have enum-behaviour using value in Flutter
MIT License
10 stars 4 forks source link

Bad state: Reflectable has not been initialized. #4

Closed Miamoto-Musashi closed 4 years ago

Miamoto-Musashi commented 4 years ago

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() ?

Miamoto-Musashi commented 4 years ago

my fault didn't fully read the documentation