简体   繁体   中英

Why can't Flutterfire connect to rtdb when compiling for MacOS? (Chrome works)

If I follow the flutterfire docs to install the flutterfire_core library and the realtime_db library, it seems I can connect to my remote firebase database when building for Chrome, but not for macOS (M1 2021 MB Pro).

The simplest example I can give you is this (myApp is unchanged from the default flutter create ):

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_database/firebase_database.dart';
import 'firebase_options.dart';



void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  await FirebaseDatabase.instance.ref().update({
    "name": "Derek",
  }).then((_) {
        print("hello");
    })
    .catchError((error) {
        print("uhoh");
    });

  runApp(const MyApp());
}

This compiles with no errors on my local machine (neither macOS nor Chrome). When building for chrome, it was able to update the remote, but not when building for macOS (it just hangs, no UI is loaded, no print statements complete). (Along the way, I did update my macOS build settings to 10.15, because I was being yelled about having things set to 10.11. When I have tried this in the past, with 10.12, things didn't work either.)

What I have tried

I have also tried to clone the example here , and it "works" (with warnings) on my machine for the Chrome build but not the macOS build.

Thank you for any help you could send my way :-)

Output of flutter --version :

Framework • revision fb57da5f94 (2 weeks ago) • 2022-05-19 15:50:29 -0700
Engine • revision caaafc5604
Tools • Dart 2.17.1 • DevTools 2.12.2

Output of flutterfire -v

0.2.2+2

Edit: Added emphasis to my main problem, and removed a warning message that has since been fixed by Rodrigo's comment.

Luckily, I was able to find this other question on StackOverFlow How do I get a Flutter project running on MacOS to successfully use Firestore? . All I needed to do was add the right network entitlements to my project.

I've never done any desktop work before, never even considered this! I think they should add it to the docs somewhere tbh. Gonna submit a request for it soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM