skip to Main Content

When I run my Flutter application on Windows 10 x64, the app crashes while listening to a document with cloud_firestore. There are no debug messages shown. Is there anyone experiencing this problem or knowing a solution?
Details are below.

Reproducing the issue

Create Flutter Project for only windows platform
flutter create --org com.clipnavi --description 'test' --platforms windows --template app test
add firebase project
dart pub global activate flutterfire_cli
flutterfire configure --project=clipspace1 check only windows and enter.
pub add
flutter pub add firebase_core
flutter pub add cloud_firestore
Open project folder with vs code.
main.dart:

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

my_home_page.dart:

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

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();

    FirebaseFirestore.instance
        .collection("status")
        .doc("eELQ6vSdSPcgM5Ha3RTyHKtBPBl1")
        .snapshots()
        .listen(
      (document) {
        print("No problem 1");
        print("current data: ${document.data()}");
      },
      onError: (error) => print("Listen failed: $error"),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("test"),
    );
  }
}

Check Firebase Database:
Firebase Database

flutter run

Firebase Core version

2.30.1

Flutter Version

3.19.6

Relevant Log Output

Launching libmain.dart on Windows in debug mode…
CMake Deprecation Warning at C:/Users/olerh/Desktop/windragon/test/build/windows/x64/extracted/firebase_cpp_sdk_windows/CMakeLists.txt:17 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.

Update the VERSION argument value or use a … suffix to tell
CMake that the project does not need compatibility with older versions.
2

√ Built buildwindowsx64runnerDebugtest.exe.
Connecting to VM Service at ws://127.0.0.1:51213/pc8BnbWb_lk=/ws
Lost connection to device.

Exited.

Flutter dependencies

Run
flutter doctor -v

[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.19045.4291], locale tr-TR)
    • Flutter version 3.19.6 on channel stable at C:flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (8 days ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:UsersolerhAppDataLocalAndroidsdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:Program FilesAndroidAndroid Studiojbrbinjava
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:Program FilesGoogleChromeApplicationchrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.6)
    • Visual Studio at C:Program FilesMicrosoft Visual Studio2022Community
    • Visual Studio Community 2022 version 17.9.34728.123
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2023.2)
    • Android Studio at C:Program FilesAndroidAndroid Studio
    • 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 17.0.9+0--11185874)

[√] VS Code (version 1.88.1)
    • VS Code at C:UsersolerhAppDataLocalProgramsMicrosoft VS Code
    • Flutter extension version 3.86.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.4291]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 124.0.6367.78
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 124.0.2478.51

[√] Network resources
    • All expected network resources are available.

• No issues found!

2

Answers


  1. This is a fatal problem for flutter windows application. I have a better solution but this is not the actual solution. Firebase and Flutter’s need to solve this problem. Now my temporary solution is clear Fire store cache on application starting before runApp() invoke. This is like:

    Future<void> main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );
      await clearFirestoreCache();
      runApp(const App());
    }
    
    Future<void> clearFirestoreCache() async {
      try {
        await FirebaseFirestore.instance.clearPersistence();
        print("Firestore cache cleared successfully.");
      } catch (e) {
        print("Failed to clear Firestore cache: $e");
      }
    }
    

    This may not work some machine.

    Login or Signup to reply.
  2. it’s not a solution but it could give someone a hint about what to do
    I have deleted the folders (firebase-heartbeat, ) in the %LOCALAPPDATA% and run the app it works then of you close it the problem will raise again

    but deleting the folders each time you run the app is not a good solution

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search