Skip to content

How to create an adapter for Parse server? #120

Answered by frank06
hinryd asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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 Results…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@hinryd
Comment options

@frank06
Comment options

Answer selected by hinryd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants