Back

Flutter, Appwrite Realtime support

  • 0
  • Flutter
  • Realtime
Nuaiman
11 Jun, 2023, 15:40

sure

TL;DR
The user is experiencing issues with Flutter and Appwrite Realtime support. They are trying to filter realtime documents but are unsure of what code to write. They provide a link to an issue on GitHub that may be helpful. The user also mentions that they are unsure of where to call the subscribe function. They mention a specific issue with their user profile not updating in real-time. Solution: The user is advised to subscribe and listen to the stream as mentioned in the Appwrite documentation. They are also directed to use three backticks for multi-line code. The user shares their code related to the user profile realtime update and asks for help.
Nuaiman
11 Jun, 2023, 15:40

Hello I have attached below all my code related to userProfiel realtime update, I have tried for several hours on my own and still cant find a solution. Please help

final appwriteRealtimeProvider = Provider((ref) { final client = ref.watch(appwriteClientProvider); return Realtime(client); }); // ------------------- Stream<RealtimeMessage> getLatestProfileData(); final userApiProvider = Provider((ref) { final db = ref.watch(appwriteDatabaseProvider); final realTime = ref.watch(appwriteRealtimeProvider); return UserApi(db: db, realtime: realTime); }); // -------------------- final getLatestUserProfileDataProvider = StreamProvider((ref) { final userApi = ref.watch(userApiProvider); return userApi.getLatestProfileData(); }); // ------------------------ import '../controller/user_profile_controller.dart'; import '../widget/user_profile.dart';

class UserProfileView extends ConsumerWidget { static route(UserModel userModel) => MaterialPageRoute( builder: (context) => UserProfileView(userModel: userModel), ); const UserProfileView({super.key, required this.userModel});

final UserModel userModel;

@override Widget build(BuildContext context, WidgetRef ref) { UserModel copyOfUser = userModel; return Scaffold( body: ref.watch(getLatestUserProfileDataProvider).when( data: (data) { if (data.events.contains( 'databases.*.collections.${AppwriteConstants.usersCollection}.documents.${userModel.uid}.update')) { copyOfUser = UserModel.fromMap(data.payload); return UserProfile(userModel: copyOfUser); } return UserProfile(userModel: copyOfUser); }, error: (error, stackTrace) => ErrorText(error: error.toString()), loading: () { return UserProfile(userModel: copyOfUser); // return Loader(); }, ), ); } }

Drake
11 Jun, 2023, 18:07

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Drake
11 Jun, 2023, 18:07

Also...what exactly is wrong? What do you expect is happening vs the actual behavior?

Nuaiman
11 Jun, 2023, 18:12

When I update my profile and and profile picture I expect it to reflect on the ui, it only happends when i restartt my app

Drake
11 Jun, 2023, 18:16

Where are you calling subscribe?

Nuaiman
11 Jun, 2023, 18:18

Aahhh!!! I am not sure where to do that

Nuaiman
11 Jun, 2023, 18:18

😬

Nuaiman
11 Jun, 2023, 18:20

I will aditionally add my link to repo, https://github.com/nuaiman/flutter_appwrite_twitter_clone

Drake
11 Jun, 2023, 18:21

Ref.when() is probably not the right approach, unless you change up the ref.

As mentioned in the docs, you have to subscribe and then listen to the stream: https://appwrite.io/docs/realtime

Nuaiman
11 Jun, 2023, 18:21

Ohhhh

Nuaiman
11 Jun, 2023, 18:21

I still dont understand, what to write

Drake
11 Jun, 2023, 18:27

Look at how the subscription is created and used

Nuaiman
11 Jun, 2023, 18:27

Okay, i will have a look at it and report back

Nuaiman
14 Jun, 2023, 16:27

@Steven hello

Nuaiman
14 Jun, 2023, 16:27

I am stuck in a situation

Nuaiman
14 Jun, 2023, 16:27

I dont know what to write for a particular realTime

Nuaiman
14 Jun, 2023, 16:27

let me exlain

Nuaiman
14 Jun, 2023, 16:28

``

Nuaiman
14 Jun, 2023, 16:28

Nuaiman
14 Jun, 2023, 16:28

'databases.${AppwriteConstants.databaseId}.collections.${AppwriteConstants.chatsCollection}.documents.'

Nuaiman
14 Jun, 2023, 16:29

I want to only get realtime document where the conversationId is matching with me

Nuaiman
14 Jun, 2023, 16:33

@Binyamin

Drake
14 Jun, 2023, 17:39

please don't randomly tag people as it can be disruptive

Drake
14 Jun, 2023, 17:40

you'll have to filter this client side.

You might want to πŸ‘πŸΌ this issue: https://github.com/appwrite/appwrite/issues/2490

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