How to debug flutter web through stack trace? - flutter

When I moved from Flutter mobile to web, I noticed that logs printed on the console are not helpful because they do not target to the code in my IDE (Android Studio)
On mobile:
======= Exception caught by widgets library =======================================================
The following message was thrown building PhoneSignUpPage(state: _PhoneSignUpPageState#b52e9):
some error
The relevant error-causing widget was:
PhoneSignUpPage file:///Users/me/AndroidStudioProjects/myproject/lib/services/routing_service.dart:30:14
When the exception was thrown, this was the stack:
#0 PhonePageViewState.initState (package:my_app/common/phone/phone_page_view.dart:63:5) // this was clickable
#1 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4711:57)
#2 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4548:5)
#3 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3611:14)
#4 Element.updateChild (package:flutter/src/widgets/framework.dart:3360:20)
...
On Web:
======== Exception caught by widgets library =======================================================
The following message was thrown building PhoneSignUpPage(state: _PhoneSignUpPageState#fb057):
some error
The relevant error-causing widget was:
PhoneSignUpPage file:///Users/me/AndroidStudioProjects/my_project/lib/services/routing_service.dart:30:14
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49 throw_
packages/my_app/common/phone/phone_page_view.dart 63:5 initState // not clickable
packages/flutter/src/widgets/framework.dart 4711:57 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4548:5 mount
packages/flutter/src/widgets/framework.dart 3611:13 inflateWidget
...
====================================================================================================
As you can see, the mobile stack trace used to be clickable but the web is not. And sometimes the StackTrace has a localhost:5000/path prefix that if clicked, leads nowhere.
I know I can check the stack trace using Chrome dev tools but I want it to be the original way, through the Android studio console, opening the file in Android Studio itself.

If you are using Android Studio then you can go to the tab Flutter Performance -> Click on Open DevTools...

To debug a flutter web, you can use the flutter logs command to print out a stack trace in the terminal.
flutter run --debug

Related

Unable to load asset, when filename has accent

i have a simple SvgPicture.asset("media/cikkcsoport/$cikkcsoportkod.svg") in my code,
and if the $cikkcsoportkod has accented value, flutter cannot load the asset.
It works with unaccented filenames, only the accented ones drop error messages like:
════════ Exception caught by SVG ═══════════════════════════════════════════════
The following assertion was thrown resolving a single-frame picture stream:
Unable to load asset: media/cikkcsoport/AÍ.svg
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:258
<asynchronous suspension>
#1 AssetBundle.loadString
package:flutter/…/services/asset_bundle.dart:83
<asynchronous suspension>
#2 AssetBundlePictureProvider._loadAsync
package:flutter_svg/src/picture_provider.dart:546
<asynchronous suspension>
Picture provider: ExactAssetPicture(name: "media/cikkcsoport/AÍ.svg", bundle: null, colorFilter: null)
Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#17a4a(), name: "media/cikkcsoport/AÍ.svg", colorFilter: null, theme: SvgTheme(currentColor: Color(0xff000000), fontSize: 14.0, xHeight: 7.0))
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by SVG ═══════════════════════════════════════════════
Unable to load asset: media/cikkcsoport/AÓ.svg
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by SVG ═══════════════════════════════════════════════
Unable to load asset: media/cikkcsoport/AÁ.svg
════════════════════════════════════════════════════════════════════════════════
How can I resolve this problem?
Try with the below things.
you have latest version on flutter_svg (https://pub.dev/packages/flutter_svg)
Added asset path in pubspec.yaml
Flutter clean & Flutter Pub get,
I hope this things are solve your issue.
I also created a test project for this issue, but I couldn't reproduce, this problem, because my svg files are renamed differently to the simulator filesystem of my test project.
I couldn't find out, what flutter settings causes the difference in the filename encoding.
Maybe I created my main flutter project from the command line, and the test project from VSCode with the Flutter: New Project function.
I can confirm, it is some argument, making the difference, at creating the flutter project.
I created a new flutter project from VSCode, and copy the relevant files to it.
Now I can open all my svg-s.

How to solve "Could not prepare isolate" error?

Installing build\app\outputs\flutter-apk\app.apk... 19.2s
E/flutter (23961): [ERROR:flutter/runtime/dart_isolate.cc(143)] Could not prepare isolate.
E/flutter (23961): [ERROR:flutter/runtime/runtime_controller.cc(385)] Could not create root isolate.
E/flutter (23961): [ERROR:flutter/shell/common/shell.cc(604)] Could not launch engine with configuration.
I do it flutter doctor but there no problem and I do it flutter clean and flutter run also but nothing run

i keep having [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) #0 MethodChannel._invokeMethod package:flutter/…/services/platform_channel.dart:175 #1 MethodChannel.invokeListMethod package:flutter/…/services/platform_channel.dart:363 #2 MethodChannelFirebase._initializeCore package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:31 #3 MethodChannelFirebase.initializeApp package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:73 #4 Firebase.initializeApp
delete the application on your emulator (or wherever you work)
execute
flutter clean
in your working directory and rebuild the app.
flutter sometimes does not recognize plugins automatically.
I had this error and deleting app on device/simulator and installing it again helped me

CircleAvatar - backgroundImage AssetImage failing to load

I am trying to load an AssetImage into a CircleAvatar but this is failing for me with the following error:
======== Exception caught by image resource service ================================================
The following assertion was thrown resolving an image codec:
Unable to load asset: images/legozombie.png
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:227:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:667:14)
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "images/legozombie.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#fe462(), name: "images/legozombie.png", scale: 1.0)
====================================================================================================
I have so far done the following:
Created a folder called images and added the file legozombie.png within my Android Studio flutter project.
Updated pubspec.yaml to contain the asset.
Run pub.get
Run get dependencies.
The images below show my folder structure, pubspec.yaml file and my code.
If anyone can please point out what I'm doing wrong, I'd appreciate this. I can state that using a NetworkImage, everything loads fine.
Any help is greatly appreciated.
Well, feels stupid now but, after I killed the iOS simulator and then relaunched it and my app, it worked fine.
Because I added a new resource, I had to stop and restart the app rather than hot loading it.

Getting error in hot reload and showing exception

I am getting following error on hot reload:
Dart Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4041 pos 12: '!_debugLocked': is not true.
Here is log:
[VERBOSE-2:shell.cc(210)] Dart Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4041 pos 12: '!_debugLocked': is not true., stack trace: #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
#2 NavigatorState.build (package:flutter/src/widgets/navigator.dart:4041:12)
#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4744:28)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4627:15)
#5 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
#6 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
#7 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
#8 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
#9 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
#<…>
Reloaded 46 of 1237 libraries in 575ms.
It looks like a problem with internal state management. In this case, the simplest solution is to hot-restart the app. Notice the difference between hot reload and hot restart: (https://flutter.dev/docs/development/tools/hot-reload)
What is the difference between hot reload, hot restart, and full restart?
Hot reload loads code changes into the VM and re-builds the widget tree, preserving the app state; it doesn’t rerun main() or initState(). (⌘\ in Intellij and Android Studio, ⌃F5 in VSCode)
Hot restart loads code changes into the VM, and restarts the Flutter app, losing the app state. (⇧⌘\ in IntelliJ and Android Studio, ⇧⌘F5 in VSCode)
Full restart restarts the iOS, Android, or web app. This takes longer because it also recompiles the Java / Kotlin / ObjC / Swift code. On the web, it also restarts the Dart Development Compiler. There is no specific keyboard shortcut for this; you need to stop and start the run configuration.