【问题标题】:"@firebase/firestore: Firestore (8.10.0): Host has been set in both settings() and useEmulator(), emulator host will be used" on Hot Refresh“@firebase/firestore:Firestore (8.10.0):主机已在 settings() 和 useEmulator() 中设置,将使用仿真器主机”热刷新
【发布时间】:2022-01-25 15:00:37
【问题描述】:

我正在尝试构建一个颤振的网络应用程序。我使用 Firebase 模拟器来测试应用程序。所以当我热刷新时,我会在标题中看到错误:

FirebaseError: Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.

我的main()

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

  String host = 'localhost';

  if (isEmulator) {
    if (!kIsWeb) {
      host = Platform.isAndroid ? '10.0.2.2' : host;
    }

    await FirebaseAuth.instance.useAuthEmulator(host, 9099);

    try {
      FirebaseFirestore.instance.useFirestoreEmulator(host, 8080);
    } on Exception catch(e){
      debugPrint('continue');
    }

    await fb_storage.FirebaseStorage.instance.useStorageEmulator(host, 9199);
    //FirebaseFunctions.instance.useFunctionsEmulator(host, 5001);

  }

  runApp(const MyApp());
}

我还将useFirestoreEmulator() 包裹在try-catch 中。但是 dart2js 转换不会将 Javascript 中的 FirebaseError 视为例外。所以我没有办法转移它。

我的颤振医生:

[√] Flutter (Channel stable, 2.8.0, on Microsoft Windows [Version 10.0.19044.1415], locale en-US)
    • Flutter version 2.8.0 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cf44000065 (2 weeks ago), 2021-12-08 14:06:50 -0800
    • Engine revision 40a99c5951
    • Dart version 2.15.0

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\muddi\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code (version 1.63.2)
    • VS Code at C:\Users\muddi\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.29.0

[√] Connected device (2 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110
    • Edge (web)   • edge   • web-javascript • Microsoft Edge 96.0.1054.62

• No issues found!

【问题讨论】:

    标签: flutter dart google-cloud-firestore flutter-web


    【解决方案1】:

    查看与您收到的错误消息相关的信息,我找到了call useEmulator after enablePersistence 的解决方案,以解决“Firestore 已启动”问题。

    现在,您需要确保所有模拟器都已启动,然后再发出请求。 我还在Stackoverflow 中发现了一个类似的问题,其中包含两个答案以及一个可能有助于解决错误消息的解决方案,一个解决方案也是使用Hot Refresh

    【讨论】:

    • 我已经看过这些解决方案了。不幸的是,问题是 Flutter 的 cloud_firebase 包中的已知错误。感谢您的帮助。
    猜你喜欢
    • 2021-03-11
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2013-12-16
    相关资源
    最近更新 更多