You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I was tracing my code, I came across this observation. On the initial load in the model.g.dart file, the data getting passed in is a _jsonMap. On the reload, the data coming in is a Map<String, dynamic>.
I assume the difference is that the first load comes from the API and the second one comes from the Hive Box? But it seems like it should always pass the same type. I thought the first load would be loaded into Hive and my code actually accessed that Hive Box. But there is definitely a difference of the types depending on which load is occurring.
Also, I realized I may have omitted a key piece of information. My model is a composite. In other words, the top level object contains a list of sub-objects. These are not sub-resources. There is no API to access them independently from the top level resource. When the top level resource is requested it contains the complete list of the sub-objects.
The top level is @DataRepository and @JsonSerializable. But the sub-object is just @JsonSerializable because I didn't need the framework to treat them as a indpendent resource. The failure is actually occuring on the sub-object (Layer) deserialization. I have attached a portion of my code to illustrate:
In case it is relevant, the database is MongoDB.
@JsonSerializable(includeIfNull: false, explicitToJson: true)
@CopyWith()
@DataRepository([ModelAdapter])
class Model extends DataModel<Model> {
Model({
this.id,
required this.name,
this.layers,
});
@override
final String? id;
final String name;
late List<Layer>? layers;
}
@JsonSerializable(includeIfNull: false, explicitToJson: true)
class Layer {
Layer({ required this.id, required this.name, });
final String id;
final String name;
// ignore: sort_constructors_first
factory Layer.fromJson(Map<String, dynamic> json) => _$LayerFromJson(json);
Map<String, dynamic> toJson() => _$LayerToJson(this);
}
Any progress? I did find a workaround. I have to sync local storage all the time. For some reason, when syncing, it takes as long to hot reload as it does to stop and start the application in debug.
Activity
boosey commentedon Nov 8, 2022
Has anyone seen this error before? Is there more information that I should provide to help diagnose?
Here are my dependencies:
frank06 commentedon Nov 8, 2022
I am reluctantly supporting Flutter Web because it's awful. Looks like a wrong cast, I'll try to reproduce soon.
boosey commentedon Nov 8, 2022
As I was tracing my code, I came across this observation. On the initial load in the model.g.dart file, the data getting passed in is a _jsonMap. On the reload, the data coming in is a Map<String, dynamic>.
I assume the difference is that the first load comes from the API and the second one comes from the Hive Box? But it seems like it should always pass the same type. I thought the first load would be loaded into Hive and my code actually accessed that Hive Box. But there is definitely a difference of the types depending on which load is occurring.
Also, I realized I may have omitted a key piece of information. My model is a composite. In other words, the top level object contains a list of sub-objects. These are not sub-resources. There is no API to access them independently from the top level resource. When the top level resource is requested it contains the complete list of the sub-objects.
The top level is @DataRepository and @JsonSerializable. But the sub-object is just @JsonSerializable because I didn't need the framework to treat them as a indpendent resource. The failure is actually occuring on the sub-object (Layer) deserialization. I have attached a portion of my code to illustrate:
In case it is relevant, the database is MongoDB.
frank06 commentedon Nov 9, 2022
I should be able to look at this next week. It would be great if you found a workaround in the meantime.
boosey commentedon Nov 17, 2022
Any progress? I did find a workaround. I have to sync local storage all the time. For some reason, when syncing, it takes as long to hot reload as it does to stop and start the application in debug.
frank06 commentedon Nov 22, 2022
No, I couldn't look at this in detail yet.
What do you mean by "sync local storage all the time"? Can you share some code? Maybe that gives me a pointer to fix this faster.
frank06 commentedon Nov 22, 2022
#185