[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'dart:ui/platform_dispatcher.dart':

This issue has been created since 2022-11-23.

I had to reinstall Flutter, Android Studio, Sdk, recreate phone emulator, recreate all my Flutter project.

I reinstalled everything to have a new, perfectly working environment.

My app works, but I see that error in log. It is linked to locale data and my app is not able to read the correct locale info from device.

Steps to Reproduce

Just running my app.

Expected results:

No error

Actual results:

Launching lib\0_main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
D/FlutterLocationService( 6491): Creating service.
D/FlutterLocationService( 6491): Binding to location service.
E/flutter ( 6491): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'dart:ui/platform_dispatcher.dart': Failed assertion: line 1840 pos 15: '<optimized out>': is not true.
E/flutter ( 6491): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter ( 6491): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter ( 6491): #2      new Locale.fromSubtags (dart:ui/platform_dispatcher.dart:1840:15)
E/flutter ( 6491): #3      PlatformDispatcher._updateLocales (dart:ui/platform_dispatcher.dart:762:29)
E/flutter ( 6491): #4      _updateLocales (dart:ui/hooks.dart:64:31)
E/flutter ( 6491): 
Debug service listening on ws://127.0.0.1:58700/eZdECN4hxJo=/ws
Syncing files to device Android SDK built for x86...
E/flutter ( 6491): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'dart:ui/platform_dispatcher.dart': Failed assertion: line 1840 pos 15: '<optimized out>': is not true.
E/flutter ( 6491): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter ( 6491): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter ( 6491): #2      new Locale.fromSubtags (dart:ui/platform_dispatcher.dart:1840:15)
E/flutter ( 6491): #3      PlatformDispatcher._updateLocales (dart:ui/platform_dispatcher.dart:762:29)
E/flutter ( 6491): #4      _updateLocales (dart:ui/hooks.dart:64:31)
E/flutter ( 6491): 
I/zygote  ( 6491): Do partial code cache collection, code=24KB, data=27KB
I/zygote  ( 6491): After code cache collection, code=24KB, data=27KB
I/zygote  ( 6491): Increasing code cache capacity to 128KB
I/zygote  ( 6491): Do partial code cache collection, code=61KB, data=50KB
I/zygote  ( 6491): After code cache collection, code=61KB, data=50KB
I/zygote  ( 6491): Increasing code cache capacity to 256KB
Code sample
Logs

flutter analyze bar spins for 15 min without output.

[√] Flutter (Channel master, 3.6.0-7.0.pre.18, on Microsoft Windows [Versione 10.0.19044.2251], locale it-IT)
    • Flutter version 3.6.0-7.0.pre.18 on channel master at C:\Users\Utente\Desktop\Cestino2\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2921ca0c48 (33 hours ago), 2022-11-21 21:43:26 -0500
    • Engine revision 8dd8e092e4
    • Dart version 2.19.0 (build 2.19.0-415.0.dev)
    • DevTools version 2.19.0

[X] Windows Version (Unable to confirm if installed Windows version is 10 or greater)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\Utente\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Users\Utente\Desktop\Cestino2\Android 2\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

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

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.3)
    • Android Studio at C:\Users\Utente\Desktop\Cestino2\Android 2\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.13+0-b1751.21-8125866)

[√] Connected device (4 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 8.0.0 (API 26) (emulator)
    • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [Versione 10.0.19044.2251]
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 107.0.5304.107
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 107.0.1418.52

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.

huycozy wrote this answer on 2022-11-24

Hi @GattoExpress999
Does this issue happen on the Flutter default sample project (counter app)? If not so, can you provide a completed and minimal reproducible code sample so that we may verify this?

GattoExpress999 wrote this answer on 2022-11-24

Yes it happens with Flutter default sample project as well, tested right now, this is the log:

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
E/flutter (12031): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'dart:ui/platform_dispatcher.dart': Failed assertion: line 1840 pos 15: '<optimized out>': is not true.
E/flutter (12031): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter (12031): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter (12031): #2      new Locale.fromSubtags (dart:ui/platform_dispatcher.dart:1840:15)
E/flutter (12031): #3      PlatformDispatcher._updateLocales (dart:ui/platform_dispatcher.dart:762:29)
E/flutter (12031): #4      _updateLocales (dart:ui/hooks.dart:64:31)
E/flutter (12031): 
E/flutter (12031): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'dart:ui/platform_dispatcher.dart': Failed assertion: line 1840 pos 15: '<optimized out>': is not true.
E/flutter (12031): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
E/flutter (12031): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
E/flutter (12031): #2      new Locale.fromSubtags (dart:ui/platform_dispatcher.dart:1840:15)
E/flutter (12031): #3      PlatformDispatcher._updateLocales (dart:ui/platform_dispatcher.dart:762:29)
E/flutter (12031): #4      _updateLocales (dart:ui/hooks.dart:64:31)
E/flutter (12031): 
Debug service listening on ws://127.0.0.1:51456/ImVCkDBlb6o=/ws
Syncing files to device Android SDK built for x86...
I/zygote  (12031): Do partial code cache collection, code=24KB, data=27KB
I/zygote  (12031): After code cache collection, code=24KB, data=27KB
I/zygote  (12031): Increasing code cache capacity to 128KB
I/zygote  (12031): Do partial code cache collection, code=61KB, data=50KB
I/zygote  (12031): After code cache collection, code=61KB, data=50KB
I/zygote  (12031): Increasing code cache capacity to 256KB
D/EGL_emulation(12031): eglMakeCurrent: 0xa7b846c0: ver 2 0 (tinfo 0x9327f5d0)

huycozy wrote this answer on 2022-11-24

@GattoExpress999 thanks for your response.
From the log, I can see you are running app on an emulator. Can you try running app on a physical device if possible? Also, please provide the output of flutter run -v. Thank you!

GattoExpress999 wrote this answer on 2022-11-25

On physical device the bug doesn't come out:

Launching lib\main.dart on 5024D EEA in debug mode...
Running Gradle task 'assembleDebug'...
√  Built build\app\outputs\flutter-apk\app-debug.apk.
Debug service listening on ws://127.0.0.1:53240/s6t13a5OXI8=/ws
Syncing files to device 5024D EEA...
D/        (13557): Gralloc Register  w:720, h:1440, f:0x1, usage:0xb00, ui64Stamp:34370, sSize:4149248, line = 2106
D/        (13557): Gralloc Register  w:720, h:1344, f:0x1, usage:0xb00, ui64Stamp:34382, sSize:3870720, line = 2106
D/        (13557): Gralloc UnRegister  w:720, h:1344, f:0x1, usage:0xb00, ui64Stamp:34346 line = 2218
D/        (13557): Gralloc UnRegister  w:720, h:1344, f:0x1, usage:0xb00, ui64Stamp:34382 line = 2218

I suppose you don't need flutter run -v

huycozy wrote this answer on 2022-11-25

@GattoExpress999 It seems the issue is only reproducible on emulator. I tried running the default Flutter project but can not reproduce this issue with Pixel 4, API 31.

Can you retry again on the latest Flutter stable channel 3.3.9 to check if this is a regression issue? And retry with another Android emulator (different API versions) if possible? Thank you!

GattoExpress999 wrote this answer on 2022-11-25
Flutter channels:
  master
  beta
* stable

Flutter 3.3.9 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b8f7f1f986 (3 days ago) • 2022-11-23 06:43:51 +0900
Engine • revision 8f2221fbef
Tools • Dart 2.18.5 • DevTools 2.15.0

News!
I tried to reinstall android 8 system image and guess what? the bug disappeared. It has been hard to understand how to because there was no way to delete image but it was always available as already downloaded. I found a "show package details" that permitted me to delete the image and so download it again.

Anyway, all the Flutter development environment is absolutelly crazy and awful. Android studio is complicated and it's not made for flutter. Very very annoying framework.

huycozy wrote this answer on 2022-11-28

Perhaps the issue is only reproducible with your old system image on the Android emulator. Android emulator has quite a few limitations that even native Android app development also faces (see https://stackoverflow.com/a/1115855/5921933).

Closing the issue as it's solved. If you disagree, please write in the comments and I will reopen it. Thanks!

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-12-10
Star Count 147243
Watcher Count 3561
Fork Count 23950
Issue Count 11325

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
[Question] Does Renovate on-prem produce metrics? 4 2022-08-11 2022-11-20
Add metrics endpoint in prometheus format 0 2022-08-16 2022-11-20
Numpad doesn't work. 0 2022-01-03 2022-09-25
Change syntax highlighting when writing to a new file 1 2022-01-02 2022-09-25
Authentication Pattern 1 2021-06-19 2022-08-21
createEconomicEvent.newInventoriedResource.name property is either not being persisted, or not being returned 1 2022-06-09 2022-11-22
once vf-graphql has Vf Module changes, update the version and update the necessary code in vf-graphql-holochain 0 2022-06-01 2022-11-22
delete .gitmodules and scripts/preinstall.sh 2 2022-06-07 2022-12-05
demo-session crashing when connected from "Media Controller Tester" 5 2022-05-20 2022-11-17
OOM Counter Incrementing Incorrectly 1 2021-09-10 2022-09-21
OptiFabric Not Working At All 0 2022-05-15 2022-07-25
关于social-media-filter.txt更新问题 2 2021-01-15 2022-11-18
Dealing with `atlasrep` data directories in a read-only system installation 2 2022-11-04 2022-11-20
crop image with custom ratio 1 2021-10-07 2022-06-28
Greater DataContractSerializer compatibility 1 2021-08-02 2022-12-05
[ bug ]docker-compose.yml 中的 hhyo/archery:1.8.2版本号有问题 2 2022-01-14 2022-10-09
`@renamedFrom` should ensure the old property isn't still present in definition 1 2022-10-31 2022-11-24
LVS mismatch in user_project_wrapper 3 2022-03-31 2022-09-10
Allow compatibility.mode for rest client to connect to ES8+ 0 2022-04-06 2022-12-03
Add group member paging 0 2020-02-03 2022-10-18
spike for 2core simulations 2 2022-06-13 2022-10-17
Conditional Validation: More then "when" 0 2021-03-10 2022-12-03
Issue / Question regarding how useForm initialState is handled 2 2022-09-12 2022-09-25
Failed when check STMP use SOCKS5 proxy 11 2021-10-18 2022-12-01
oracelreader设置column为["*"],设置splitPk为"ROW_NUMBER()"时,报错:ora00923 FROM key word not found 0 2022-01-19 2022-02-13
Two 'helpers' and 'assertions', unclear which one has what and when should be used 2 2021-11-22 2022-11-24
Autodiff gives wrong results given the local atomics 0 2022-03-01 2022-08-07
pm2 issue 0 2021-07-13 2022-01-06
NODE_APP_INSTANCE is always 0 in cluster mode 3 2021-07-09 2022-10-30
fsync issues 20 2021-08-17 2022-01-13
Compiled JSON Patch 0 2021-11-03 2022-01-21
Auto-heal NAT Instances 2 2020-08-26 2022-12-02
workload/schemachange: sanity check that the workload did things 0 2022-05-26 2022-12-04
getFileAsync returns 5001 with PDF file open in Word 6 2022-07-01 2022-11-12
Deprecation notice required: [php-buildpack] nginx version 1.18.x*** 1 2021-06-17 2022-10-20
expand: Variable cannot represent indexed arrays with gaps 6 2021-02-24 2022-12-05
Add Back to home 2 2021-12-13 2022-01-15
`render-tests/video/projected` test is flaky 0 2021-11-05 2022-10-17
`BatchFeature` performance improvement: convert `List[np.ndarray]` to `np.ndarray` before converting to pytorch tensors 4 2021-11-07 2022-10-07
Predictions for pre-tokenized tokens with Roberta have strange offset_mapping 9 2021-11-06 2022-09-28
43页调用 selectedKeySet()的 对象应该是Selector 2 2021-08-01 2022-11-28
Change Progress default color 1 2020-06-03 2022-12-05
Compatibility with plotly 5 2 2021-11-11 2022-12-03
upgrade `add_weighted` to accept weights as tensors 4 2022-08-14 2022-09-02
Tabbed sections 4 2018-03-16 2022-01-15
Translate 'library/stdtypes.po' 2 2021-08-09 2022-11-12
Update: lein 2.9.5 0 2020-12-09 2021-12-05
test failed in http/file_server_test.ts error: Uncaught TypeError: Must be a file URL. 2 2022-05-10 2022-10-10
InApp Browser to be brave when the Default browser is different one.... 0 2022-05-31 2022-11-09
In tf_Agents, Is there a way to retrain the environment order/sequence of generated observations in the driver and replay buffer 0 2022-05-04 2022-12-01