Back

Best Practices for Handling Entity Conflicts when Integrating Appwrite with Clean Architecture

  • 0
  • Users
  • Accounts
  • General
  • Flutter
devme
29 Sep, 2023, 11:34

Hello Flutter developers and Appwrite enthusiasts!

I'm currently implementing a clean architecture in my Flutter app, and I've encountered a challenge when integrating Appwrite. In my clean architecture, I have my own custom User entity and model.

The issue arises when I interact with Appwrite, which provides its own User entity. This creates a conflict where I'm getting the following error:

value of type User (where User is defined in ...appwrite...) can't be assigned to a variable of type 'User (where User is defined in ...my project...)'.

I understand this is due to the clash between the User entity from Appwrite and my custom User entity. Has anyone faced a similar issue, and what approach would you recommend to resolve this conflict while maintaining a clean architecture?

Here are a few specific questions:

1- Is it common to use the User class from Appwrite directly throughout the project, or should I prefer my custom User entity?

2- How do you handle the mapping between Appwrite's User and your custom User entity/model in your application?

3- Are there any recommended strategies for managing entities and models to keep them distinct and avoid such conflicts in a clean architecture?

I appreciate any guidance, experiences, or best practices you can share to navigate this challenge effectively.

Thank you!

TL;DR
I'm implementing clean architecture in my Flutter app and encountering a conflict between Appwrite's User entity and my custom User entity. I'm getting an error due to the clash between the two. 1. It is common to use the User class from Appwrite directly, but you can use your custom User entity if preferred. 2. To handle the mapping, you can convert your preferred fields to a custom data model and use Appwrite Functions for updates. 3. Recommended strategies for managing entities and models in a clean architecture include changing the name of the custom data class or giving a prefix to the imported custom User model. These
james54
29 Sep, 2023, 11:53

About your issue of different datatypes error there are two ways :

  1. Change name of your custom data class
  2. When you import your custom User on top of your file give it a prefix then access User model using that prefix
james54
29 Sep, 2023, 11:58

for specific questions :

  1. As far as i know it depends on your usecase.
  2. It should be pretty simple (convert your preffered fields to a custom data model), for handling updates you can use Appwrite Functions.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more