Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Crash on AppConfig factory constructor when used with JsonSerializable #5

Open
zirinisp opened this issue May 10, 2018 · 3 comments
Open

Comments

@zirinisp
Copy link

I am totally new to Dart and Flutter, so my knowledge is quite limited.

I am getting the following error when I use your factory contructor. The error happens a couple of seconds after the app is launching on iPhone.

Performing full restart...
Restarted app in 2,563ms.
[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type 'YamlMap' is not a subtype of type 'Map<String, dynamic>' where
YamlMap is from package:yaml/src/yaml_node.dart
Map is from dart:core
String is from dart:core

#0 new AppConfig.fromJson (package:letsvote/model.dart:91:59)
#1 ConfigService.parseYaml (package:letsvote/services.dart:36:16)
#2 FlutterConfigService.loadConfig (package:letsvote_mobile/services.dart:15:12)

#3 AppController.init (package:letsvote/controllers.dart:30:41)

#4 _PageContainerState.initState (package:letsvote_mobile/widgets/letsvote.dart:74:19)
#5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3743:58)
#6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3609:5)
#7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2899:14)
#8 Element.updateChild (package:flutter/src/widgets/framework.dart:2702:12)
#9 ComponentEle<…>

If I do not use JsonSerializable and do the initialization my self (using the code inside the comments) it works without issues:

@JsonSerializable()
class AppConfig extends _$AppConfigSerializerMixin {
  final String host;
  AppConfig(this.host);
  /*
  factory AppConfig.fromJson(json) {
    String host = json['host'];
    return new AppConfig(host);
  }*/

  factory AppConfig.fromJson(json) => _$AppConfigFromJson(json);
}

As I said I am totally new to this and was inspired by your talks and articles on using dart for Web/Mobile, so I am trying to find my way around it.

@johnpryan
Copy link
Owner

It looks like this app needs to be upgraded to Dart 2. For now, can you run with the--no-preview-dart-2 flag?

@zirinisp
Copy link
Author

Thank you for the prompt reply.

I managed to get it running with the code in the comments.

It is a very nice example as it combines exactly what I want out of Dart (mobile and web). Dart 2 does not make the learning process easy, as many things have been broken.

If you update it to Dart 2.0 please send me a message on this issue. I will also keep an eye.

@johnpryan
Copy link
Owner

Thanks! Upgrading to Dart 2 will take some effort; it most likely involve switching the web app from Polymer to AngularDart. But I think it would be a good idea :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants