flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [cloud_firestore, windows] Channel sent a message from native to Flutter on a non-platform thread

Open perret123 opened this issue 1 year ago • 20 comments
trafficstars

Bug report

Thank you very much for implementing Windows Support for Firestore! My console is full of the following errors though:

Describe the bug

[ERROR:flutter/shell/common/shell.cc(1015)] The 'plugins.flutter.io/firebase_firestore/document/73aacdf9-bdef-4567-bfea-497071865252' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.
See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information.

Steps to reproduce

Steps to reproduce the behavior:

  1. Run Example-App for Windows
  2. Look at console
  3. See error

Expected behavior

No error :-)

Sample project

https://github.com/firebase/flutterfire/tree/master/packages/cloud_firestore/cloud_firestore/example


Additional context

Maybe it has something similar as with this issue that was fixed for Firebase Database already; https://github.com/firebase/flutterfire/issues/11628


Flutter doctor

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.16.0, on Microsoft Windows [Version 10.0.22621.2715], locale de-CH)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.5)
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.84.2)
[√] Connected device (6 available)
[√] Network resources

• No issues found!

Flutter dependencies

Click To Expand
Dart SDK 3.2.0
Flutter SDK 3.16.0
cloud_firestore_example 0.0.0

dependencies:
- cloud_firestore 4.13.2 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 2.23.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine]
- http 0.13.6 [async http_parser meta]

dev dependencies:
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web]
- integration_test 0.0.0 [flutter flutter_driver flutter_test path vm_service async boolean_selector characters clock collection fake_async file matcher material_color_utilities meta source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api vector_math web webdriver]

transitive dependencies:
- _flutterfire_internals 1.3.13 [collection firebase_core firebase_core_platform_interface flutter meta]
- async 2.11.0 [collection meta]
- boolean_selector 2.1.1 [source_span string_scanner]
- characters 1.3.0
- clock 1.1.1
- cloud_firestore_platform_interface 6.0.6 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 3.8.6 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.18.0
- fake_async 1.3.1 [clock collection]
- file 6.1.4 [meta path]
- firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.8.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- flutter_driver 0.0.0 [file flutter flutter_test fuchsia_remote_debug_protocol path meta vm_service webdriver async boolean_selector characters clock collection matcher material_color_utilities platform process source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api vector_math web]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web]
- fuchsia_remote_debug_protocol 0.0.0 [process vm_service file meta path platform]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- js 0.6.7 [meta]
- matcher 0.12.16 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.5.0 [collection]
- meta 1.10.0
- path 1.8.3
- platform 3.1.2
- plugin_platform_interface 2.1.7 [meta]
- process 4.2.4 [file path platform]
- sky_engine 0.0.99
- source_span 1.10.0 [collection path term_glyph]
- stack_trace 1.11.1 [path]
- stream_channel 2.1.2 [async]
- string_scanner 1.2.0 [source_span]
- sync_http 0.3.1
- term_glyph 1.2.1
- test_api 0.6.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- typed_data 1.3.2 [collection]
- vector_math 2.1.4
- vm_service 11.10.0
- web 0.3.0
- webdriver 3.0.2 [matcher path stack_trace sync_http]

perret123 avatar Nov 22 '23 21:11 perret123

Same issue!!

patricknicolosi avatar Nov 22 '23 22:11 patricknicolosi

Thanks for the report. Reproduced the issue using plugin example. Even though the error is thrown, the project can be built and app is opened normally.

flutter doctor -v
[√] Flutter (Channel stable, 3.16.0, on Microsoft Windows [Version 10.0.19045.3693], locale en-US)
    • Flutter version 3.16.0 on channel stable at C:\WIP\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db7ef5bf9f (6 days ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

[√] 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:\AndroidSDK
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = C:\AndroidSDK
    • Java binary at: C:\Program Files\Android\Android StudioGiraffe\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
    • All Android licenses accepted.

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

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.4.4)
    • Visual Studio at D:\DOWNLOADWORK\VS2022
    • Visual Studio Community 2022 version 17.4.33213.308
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\Android 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 11.0.12+7-b1504.28-7817840)

[√] Android Studio (version 2022.3)
    • Android Studio at C:\Program Files\Android\Android StudioGiraffe
    • 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.6+0-b2043.56-10027231)

[√] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\Android\Android Studio Electric Eel 2022.1.1
    • 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.13+0-b1751.21-8125866)

[√] VS Code (version 1.84.2)
    • VS Code at C:\Users\ADMIN\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.76.0

[√] Connected device (4 available)
    • RMX2001 (mobile)  • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
    • Windows (desktop) • windows          • windows-x64    • Microsoft Windows [Version 10.0.19045.3693]
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 119.0.6045.160
    • Edge (web)        • edge             • web-javascript • Microsoft Edge 119.0.2151.72

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

• No issues found!

huycozy avatar Nov 23 '23 11:11 huycozy

Blocked by Flutter: https://github.com/flutter/flutter/issues/134346

Lyokone avatar Nov 23 '23 12:11 Lyokone

getting same issue and data is not being loaded from firebase

The 'plugins.flutter.io/firebase_firestore/query/7b4620e3-2aa0-4ea0-b2c0-0b27878c3b00' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.

AliYar-Khan avatar Dec 07 '23 08:12 AliYar-Khan

+1 on this issue. There was a recent update to the cloud_firestore package but after updating to the latest version 4.13.5 the issue persists

[ERROR:flutter/shell/common/shell.cc(1015)] The 'plugins.flutter.io/firebase_firestore/query/8bdadc9e-3ac2-42f0-92f1-06427838f097' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.

daviddavis83 avatar Dec 09 '23 16:12 daviddavis83

I'm also having this issue

dannycortesv avatar Dec 18 '23 14:12 dannycortesv

v 4.15.8 still happening

GumDeveloper avatar Mar 11 '24 10:03 GumDeveloper

Instead of spamming this issue with +1 comments, consider thumbing up the underlying issue:https://github.com/flutter/flutter/issues/134346

Lyokone avatar Mar 11 '24 10:03 Lyokone

Instead of spamming this issue with +1 comments, consider thumbing up the underlying issue:flutter/flutter#134346

You are right, sorry, should have read properly. Kind regards.

GumDeveloper avatar Mar 11 '24 11:03 GumDeveloper

I think the +1 button is broken seems to add months.

cyberpwnn avatar Jul 11 '24 01:07 cyberpwnn

Same issue

visvajeet avatar Nov 22 '24 08:11 visvajeet

Is there any solution on this?

The problem is still there. The project can be built, but there are problems. The first time in firebaseAuth.userChanges I always get null (only on Windows). I think it is related to this.

But the bigger problem is that after the email verification I get firebaseAuth.userChanges with isEmailVerified: true, and this: [ERROR:flutter/shell/common/shell.cc(1065)] The 'firebase_auth_plugin/id-token/[DEFAULT]' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel. See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information. After that I restart the app and I get firebaseAuth.userChanges with isEmailVerified: false again.

ndevev avatar Jan 16 '25 09:01 ndevev

Same, any solution?

ColdAndDark avatar Jan 20 '25 10:01 ColdAndDark

I have this issue as well, building works fine even though the errors appear in the debug console. But once I attempt to execute a certain method the app crashes. I have an example project I can share if needed. Just let me know. (This is for windows)

Eldr1tchTech avatar Apr 10 '25 05:04 Eldr1tchTech

Same :////

202745EsquedaDaniel avatar Jun 02 '25 19:06 202745EsquedaDaniel

I have since quit flutter, I don’t mean to be dramatic, but I just don’t want to work with a project that has bugs like this with either no well documented fixes, or the issue has been fixed entirely. Through what my research has yielded it seems to be an issue on the flutter side… sigh

Eldr1tchTech avatar Jun 02 '25 19:06 Eldr1tchTech

Hi everyone,

I wanted to share a workaround that helped me mitigate the issue where Firestore sends native messages from non-platform threads on Windows, causing errors and sometimes crashes.

The problem seems related to leftover cached state causing native callbacks on improper threads. The key is to clear Firestore’s local persistence cache right after initializing Firebase and before using Firestore anywhere in the app.

Here’s what I did:

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

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

// ⚠️ Important: Clear Firestore cache to avoid thread errors on Windows await clearFirestoreCache();

runApp(MyApp()); }

Future clearFirestoreCache() async { try { await FirebaseFirestore.instance.clearPersistence(); print("Firestore cache cleared successfully."); } catch (e) { print("Failed to clear Firestore cache: $e"); } } `

By clearing the cache early during startup this way, I was able to prevent many of the recurring non-platform thread errors and reduce app crashes caused by this issue.

202745EsquedaDaniel avatar Jun 05 '25 18:06 202745EsquedaDaniel

I have since quit flutter, I don’t mean to be dramatic, but I just don’t want to work with a project that has bugs like this with either no well documented fixes, or the issue has been fixed entirely. Through what my research has yielded it seems to be an issue on the flutter side… sigh

Temporally solved my friend @Eldr1tchTech @huycozy

202745EsquedaDaniel avatar Jun 05 '25 18:06 202745EsquedaDaniel

Hi everyone,

I wanted to share a workaround that helped me mitigate the issue where Firestore sends native messages from non-platform threads on Windows, causing errors and sometimes crashes.

The problem seems related to leftover cached state causing native callbacks on improper threads. The key is to clear Firestore’s local persistence cache right after initializing Firebase and before using Firestore anywhere in the app.

Here’s what I did:

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

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

// ⚠️ Important: Clear Firestore cache to avoid thread errors on Windows await clearFirestoreCache();

runApp(MyApp()); }

Future clearFirestoreCache() async { try { await FirebaseFirestore.instance.clearPersistence(); print("Firestore cache cleared successfully."); } catch (e) { print("Failed to clear Firestore cache: $e"); } } `

By clearing the cache early during startup this way, I was able to prevent many of the recurring non-platform thread errors and reduce app crashes caused by this issue.

Hi @202745EsquedaDaniel , thank you for this workaround, however do you happen to know a solution for the same error but for Firebase Storage?

jingfeng-cheah avatar Jun 06 '25 04:06 jingfeng-cheah

Hi everyone,

I wanted to share a workaround that helped me mitigate the issue where Firestore sends native messages from non-platform threads on Windows, causing errors and sometimes crashes.

The problem seems related to leftover cached state causing native callbacks on improper threads. The key is to clear Firestore’s local persistence cache right after initializing Firebase and before using Firestore anywhere in the app.

Here’s what I did:

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

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

// ⚠️ Important: Clear Firestore cache to avoid thread errors on Windows await clearFirestoreCache();

runApp(MyApp()); }

Future clearFirestoreCache() async { try { await FirebaseFirestore.instance.clearPersistence(); print("Firestore cache cleared successfully."); } catch (e) { print("Failed to clear Firestore cache: $e"); } } `

By clearing the cache early during startup this way, I was able to prevent many of the recurring non-platform thread errors and reduce app crashes caused by this issue.

Hi, thank you for sharing this. I'm happy it worked for you, but it doesn't fix anything in my case. It's not just related to caching 😢

jmgeffroy avatar Jun 12 '25 10:06 jmgeffroy

Hi everyone, I wanted to share a workaround that helped me mitigate the issue where Firestore sends native messages from non-platform threads on Windows, causing errors and sometimes crashes. The problem seems related to leftover cached state causing native callbacks on improper threads. The key is to clear Firestore’s local persistence cache right after initializing Firebase and before using Firestore anywhere in the app. Here’s what I did: import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); // ⚠️ Important: Clear Firestore cache to avoid thread errors on Windows await clearFirestoreCache(); runApp(MyApp()); } Future clearFirestoreCache() async { try { await FirebaseFirestore.instance.clearPersistence(); print("Firestore cache cleared successfully."); } catch (e) { print("Failed to clear Firestore cache: $e"); } } By clearing the cache early during startup this way, I was able to prevent many of the recurring non-platform thread errors and reduce app crashes caused by this issue.

Hi @202745EsquedaDaniel , thank you for this workaround, however do you happen to know a solution for the same error but for Firebase Storage?

It should works

202745EsquedaDaniel avatar Jun 17 '25 14:06 202745EsquedaDaniel

Hi everyone, I wanted to share a workaround that helped me mitigate the issue where Firestore sends native messages from non-platform threads on Windows, causing errors and sometimes crashes. The problem seems related to leftover cached state causing native callbacks on improper threads. The key is to clear Firestore’s local persistence cache right after initializing Firebase and before using Firestore anywhere in the app. Here’s what I did: import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); // ⚠️ Important: Clear Firestore cache to avoid thread errors on Windows await clearFirestoreCache(); runApp(MyApp()); } Future clearFirestoreCache() async { try { await FirebaseFirestore.instance.clearPersistence(); print("Firestore cache cleared successfully."); } catch (e) { print("Failed to clear Firestore cache: $e"); } } By clearing the cache early during startup this way, I was able to prevent many of the recurring non-platform thread errors and reduce app crashes caused by this issue.

Hi, thank you for sharing this. I'm happy it worked for you, but it doesn't fix anything in my case. It's not just related to caching 😢

What is your issue?

202745EsquedaDaniel avatar Jun 17 '25 14:06 202745EsquedaDaniel

Hi everyone, I wanted to share a workaround that helped me mitigate the issue where Firestore sends native messages from non-platform threads on Windows, causing errors and sometimes crashes. The problem seems related to leftover cached state causing native callbacks on improper threads. The key is to clear Firestore’s local persistence cache right after initializing Firebase and before using Firestore anywhere in the app. Here’s what I did: import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); // ⚠️ Important: Clear Firestore cache to avoid thread errors on Windows await clearFirestoreCache(); runApp(MyApp()); } Future clearFirestoreCache() async { try { await FirebaseFirestore.instance.clearPersistence(); print("Firestore cache cleared successfully."); } catch (e) { print("Failed to clear Firestore cache: $e"); } } By clearing the cache early during startup this way, I was able to prevent many of the recurring non-platform thread errors and reduce app crashes caused by this issue.

Hi @202745EsquedaDaniel , thank you for this workaround, however do you happen to know a solution for the same error but for Firebase Storage?

It should works

Thank you for your reply @202745EsquedaDaniel but your solution is for Firestore, was wondering about Firebase Storage instead

jingfeng-cheah avatar Jun 18 '25 03:06 jingfeng-cheah

Same issue! 🤕 Any suggestion?

manuel-velascodev avatar Jul 03 '25 21:07 manuel-velascodev

Hi everyone, I wanted to share a workaround that helped me mitigate the issue where Firestore sends native messages from non-platform threads on Windows, causing errors and sometimes crashes. The problem seems related to leftover cached state causing native callbacks on improper threads. The key is to clear Firestore’s local persistence cache right after initializing Firebase and before using Firestore anywhere in the app. Here’s what I did: import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); // ⚠️ Important: Clear Firestore cache to avoid thread errors on Windows await clearFirestoreCache(); runApp(MyApp()); } Future clearFirestoreCache() async { try { await FirebaseFirestore.instance.clearPersistence(); print("Firestore cache cleared successfully."); } catch (e) { print("Failed to clear Firestore cache: $e"); } } By clearing the cache early during startup this way, I was able to prevent many of the recurring non-platform thread errors and reduce app crashes caused by this issue.

Hi @202745EsquedaDaniel , thank you for this workaround, however do you happen to know a solution for the same error but for Firebase Storage?

It should works

Thank you for your reply @202745EsquedaDaniel but your solution is for Firestore, was wondering about Firebase Storage instead

Here's my fix for Firebase Storage uploading on Windows that was crashing for me in my app MOLLY Gist: https://gist.github.com/b0bben/3cdab1c55c6ad86e282c4d6e56d204ae

b0bben avatar Jul 14 '25 14:07 b0bben

@b0bben Hi, so your solution is adding the "WidgetsBinding.instance.addPostFrameCallback" ?

jingfeng-cheah avatar Jul 15 '25 02:07 jingfeng-cheah

@b0bben Hi, so your solution is adding the "WidgetsBinding.instance.addPostFrameCallback" ?

Yes, this enabled me to upload files without crashes. My app was crashing on uploads because the onProgress event was being sent on non-main thread from native side, and this helped. It's an ugly workaround that stopped the crashes. Proper progress tracking will be lost (on windows), but it won't crash and upload will work.

b0bben avatar Jul 15 '25 08:07 b0bben

Thanks for your suggestion @b0bben, but have you tried uploading a large number of big images? I tried uploading with 160 images and it crashes after reaching about 20 images 😢

jingfeng-cheah avatar Jul 31 '25 07:07 jingfeng-cheah