Skip to content

Realtime to non avail in Flutter #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TomTom101 opened this issue Nov 14, 2022 · 4 comments
Closed

Realtime to non avail in Flutter #16

TomTom101 opened this issue Nov 14, 2022 · 4 comments

Comments

@TomTom101
Copy link

I cannot get realtime to work neither w/ pocketbase 0.7.10 and the Dart SDK 0.4.1 nor 0.8.0-rc2 and SDK version 0.5.0-rc2.

This is my test app for pocketbase 0.7.10 and the Dart SDK 0.4.1. I created a collection items and and a user with the given credentials. The pocketbase debug log shows "Realtime connection established …" but any change in the items collections would trigger the passed function in subscribe.

import 'package:flutter/material.dart';
import 'package:pocketbase/pocketbase.dart';

void main() {
  runApp(MainApp());
}

class MainApp extends StatelessWidget {
  MainApp({super.key});

  final client = PocketBase('http://127.0.0.1:8090');

  @override
  Widget build(BuildContext context) {
    void signIn() async {
      final userData = await client.users
          .authViaEmail('[email protected]', '1234567890');

      // Successfully establishes a connection, debug output is "Realtime connection established: bNuGMnn9Pmsdh9gCnkIWxnFRrL8JvYCS92ccWJLL"
      client.realtime.subscribe("items", (e) {
        // updating, inserting, deleting does not fire this function here
        print("Changed main $e");
      });
    }

    return MaterialApp(
      home: Center(
        child: ElevatedButton(
          onPressed: signIn,
          child: const Text("Realtime"),
        ),
      ),
    );
  }
}

The network shows a single GET call to /api/realtime whereas a sample React app I tested, and which works fine with realtime, additionally POSTs subscriptions etc.

Can someone post a minimal Flutter with working realtime subscriptions?

@TomTom101 TomTom101 changed the title Relative to non avail in Flutter Realtime to non avail in Flutter Nov 14, 2022
@TomTom101
Copy link
Author

Just saw this "Streamed responses (used by the realtime service) are not supported on the web". I guess this answers my questions, realtime is not supported on the web plattform. What a bugger. Anyhow, lovely project, this!

@ganigeorgiev
Copy link
Member

ganigeorgiev commented Nov 14, 2022

@TomTom101 Yes, that's correct. Currently the Dart SDK realtime service doesn't work on the web platform. There are workarounds, eg. using the browser EventSource js-interop and/or use fetch to send the request, but it would be better and more maintainable in the long run if it is added in the dart http client (you can subscribe to this issue - dart-lang/http#595).

I'll close the issue for now as it is known limitation, but if someone else think that it is worth investing the time creating a workaround, please let me know and depending on the users demand I may reconsider implementing it.

@TomTom101
Copy link
Author

Thanks Gani! I am a bit spoiled with Firebase's Firestore where I simply listen to a stream and never have to worry about updating datasets anywhere. I'd sure be interested on how to replicate a similar behavior with Pocketbase, ideally in combination with Riverpod.

@agreensh
Copy link

I would be interested in a workaround for this issue now (who knows how long Dart will take to be updated).
Currently, I cannot use pocketbase because of this limitation on the web.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants