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

Crash on AppConfig factory constructor when used with JsonSerializable #5

@zirinisp

Description

@zirinisp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions