'Error: Expected a value of type 'int', but got one of type 'String'
Error: Expected a value of type 'int', but got one of type 'String'
at Object.throw_ [as throw] (http://localhost:50026/dart_sdk.js:5405:11)
at Object.castError (http://localhost:50026/dart_sdk.js:5362:15)
at Object.cast [as as] (http://localhost:50026/dart_sdk.js:5686:17)
at dart.LegacyType.new.as (http://localhost:50026/dart_sdk.js:7363:60)
at new module_model.ModuleModel.fromJson (http://localhost:50026/packages/sixam_mart/data/model/response/module_model.dart.lib.js:161:29)
at new config_model.ConfigModel.fromJson (http://localhost:50026/packages/sixam_mart/data/model/response/config_model.dart.lib.js:614:51)
at splash_controller.SplashController.new.getConfigData (http://localhost:50026/packages/sixam_mart/data/repository/auth_repo.dart.lib.js:51322:35)
at getConfigData.next (<anonymous>)
at http://localhost:50026/dart_sdk.js:43063:33
at _RootZone.runUnary (http://localhost:50026/dart_sdk.js:42919:58)
at _FutureListener.thenAwait.handleValue (http://localhost:50026/dart_sdk.js:37493:29)
at handleValueCallback (http://localhost:50026/dart_sdk.js:38088:49)
at Function._propagateToListeners (http://localhost:50026/dart_sdk.js:38126:17)
at _Future.new.[_completeWithValue] (http://localhost:50026/dart_sdk.js:37955:23)
at http://localhost:50026/dart_sdk.js:38193:40
at _RootZone.runUnary (http://localhost:50026/dart_sdk.js:42919:58)
at _FutureListener.then.handleValue (http://localhost:50026/dart_sdk.js:37493:29)
at handleValueCallback (http://localhost:50026/dart_sdk.js:38088:49)
at Function._propagateToListeners (http://localhost:50026/dart_sdk.js:38126:17)
at _Future.new.[_completeWithValue] (http://localhost:50026/dart_sdk.js:37955:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:50026/dart_sdk.js:37991:35)
at Object._microtaskLoop (http://localhost:50026/dart_sdk.js:43223:13)
at _startMicrotaskLoop (http://localhost:50026/dart_sdk.js:43229:13)
at http://localhost:50026/dart_sdk.js:38359:9
I've been dealing with this problem for days, I wasn't getting such a problem before, I changed computers, zero files and the same problem, how can I solve it I'm new to flutter
It builds but does not open the application and at the same time, when I open debug, I get the same error. The application does not open.
class ModuleModel {
int id;
String moduleName;
String moduleType;
String thumbnail;
String icon;
int themeId;
String description;
int storesCount;
String createdAt;
String updatedAt;
ModuleModel(
{this.id,
this.moduleName,
this.moduleType,
this.thumbnail,
this.storesCount,
this.icon,
this.themeId,
this.description,
this.createdAt,
this.updatedAt,
});
ModuleModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
moduleName = json['module_name'];
moduleType = json['module_type'];
thumbnail = json['thumbnail'];
icon = json['icon'];
themeId = json['theme_id'];
description = json['description'];
storesCount = json['stores_count'];
createdAt = json['created_at'];
updatedAt = json['updated_at'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['module_name'] = this.moduleName;
data['module_type'] = this.moduleType;
data['thumbnail'] = this.thumbnail;
data['icon'] = this.icon;
data['theme_id'] = this.themeId;
data['description'] = this.description;
data['stores_count'] = this.storesCount;
data['created_at'] = this.createdAt;
data['updated_at'] = this.updatedAt;
return data;
}
}
Solution 1:[1]
Add the following debugging code:
ModuleModel.fromJson(Map<String, dynamic> json) {
print(json);
print(json['id'].runtimeType);
print(json['theme_id'].runtimeType);
print(json['stores_count'].runtimeType);
id = json['id'];
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Richard Heap |