-
Just stumbled across this library seems to solve my data problems, there are a few questions as the documentation is sparse.
Below is an example of the response:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @hinryd , I'm working on the new docs as we speak! I hope to have them up this week. In Flutter Data we use adapters to override behavior. Let's assume your model is called (1) We need to pass the deserializer a different root, so we override it: mixin PlayerAdapter on RemoteAdapter<Player> {
@override
DeserializedData<T, DataModel> deserialize(Object? data,
{String? key}) {
// whatever condition makes sense for your data
if (data['results'] is Iterable) {
return super.deserialize(data['results'], key: key);
}
return super.deserialize(data, key: key);
}
} If all your models have this behavior (not only players) you can use it like mixin ResultsAdapter<T extends DataModel<T>> on RemoteAdapter<T> { } In the model include the adapter and specify a new ID for (2) which really is a @DataRepository([PlayerAdapter])
@JsonSerializable()
class Player with DataModel<Player> {
@override
@JsonKey(name: 'objectId') final String? id;
final String playerName;
final int score;
// ...
final BelongsTo<Family> family;
Person({
this.id,
required this.playerName,
this.score,
// ...
}); Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hi @hinryd , I'm working on the new docs as we speak! I hope to have them up this week.
In Flutter Data we use adapters to override behavior.
Let's assume your model is called
Player
.(1) We need to pass the deserializer a different root, so we override it:
If all your models have this behavior (not only players) you can use it like