How to get stacktrace from Flutter? - flutter

I have a Android/iOS app developed using Flutter through Visual Studio Code. When I run it on Android >=5.0 or any version of iOS it works flawlessly, however it crashes immediately when I run it on Android 4.x (Unfortunately, app has stopped).
I want to fix it, but Flutterdoesn't show me what is happening.
I tried to run through VSCode pushing F5 button and also using command line flutter run, but neither shows me something that I could work with. I tried to run with trace command [Flutter trace run], but it says The --debug-port argument must be specified and I don't know what it means.
I just need a stacktrace or a line error showing me what is the problem. Do I have to configure something on VSCode?

There's a Debug Console available in Visual Studio Code as per checking version 1.51.1. This can be enabled/disabled by navigating through the menu View > Debug Console. Both logs from Android emulator and iOS simulator can be displayed on the Debug Console.
However, if you're looking into checking Flutter debug logs outside of Visual Studio Code, the adb logcat command using the terminal works well for Android as previously mentioned in the comments.
On iOS, one way of checking the logs is through the Console. Press ⌘ + space and type "Console", and press Enter to launch the app. The iOS device should be displayed on the left-side pane of the Console app under Devices. Clicking on the iOS device should display its logs.

Related

Flutter app is not showing as an icon on the android emulator homescreen

I am trying to build an app. I am using flutter as the framework and VS Code as my IDE. I also have an android emulator installed via android studio. I am trying to implement authentication. If i run my app it opens in the emulator and works just fine. Now i want to test if a user stays logged in when the app is closed (not running in the background) and reopened. However if i close the app in the android emulator, the whole process stops and there is no icon of my app on the home screen with which i could restart it. I have to "run and debug" again in VS Code to restart the process. Is there any way to start the app again via the emulator phone?
I updated the emulator and the flutter package, i changed emulator devices. Did not solve the problem.
Because when your app is disconnected from debug - you can use hot restart its consider as app is kill and open again - here having a problem with flutter if you disconnect from debug your all assets will be remove from entire app. Another option - if you want to test your app then make release app and installed in physical device
You can try to run your app from VS Code itself.
Use this bottom Menu button to launch emulator:
Select your Emulator from listed / Create a new one:
Hope it helps!

Flutter run never loads on vs code and sometimes crashes on android studio on my chromebook

I recently installed Flutter on my Chromebook (4 GB RAM). I have been writing snippets of dart code using vscode with no issues. Recently, I decided to move into the flutter framework, and then when I try to run the default application generated after creating a new project, VS Code freezes after a while. I know initially this was supposed to take a while to load being my first time, but is over 1 hour the appropriate time?
I have tried restarting VS Code several times, but still the same output. I even switched to using Android Studio, and this even crashes after a while.
What could be wrong or what am I getting wrong? I followed the official installation process on both VS Code and Flutter.dev sites.
i will assume that you have set up your emulator correctly and you opened the emulator with these steps:
1- on your keyboard use ctrl + shift + p and choose Flutter: Select Device and wait for the emulator to open.
2- after the emulator starts, from the upper menu of VSCode select Run > Run without debugging.
the app should run, if the problem persists, in VSCode open a new terminal window and type :
1- flutter upgrade
2- flutter clean
3- flutter pub get
try to run the application hopefully it will run

How to run emulator outside android studio?

I am using Android Studio bumbleBee version in Windows 10 . Appears in a window when I run the emulator. My monitor is small and it is better to have it separately as before.
There are three methods that I can think of.
Thanks to #vishal beep answer, You can simply go to file => setting=>search emulator in the search field=>select emulator=>uncheck launch in a tool window. Screenshot below.
Since it is a flutter project Instead of going to device manager you can simply
Click on the device list first and
Select Refresh if you don't see your emulator
Once refreshed you should be able to see the emulator like the screenshot below.
select the emulator, and run your application.
.
3. Or you can run the emulator as usual and then right-click on the emulator window and choose View mode=>Select Float option instead of Docked Pinned screenshot attached below
Thanks, Keep coding
Go to setting -> tools ->emulator and unselecte launch in a tool windows
Simply Go to Preferences.. >Tools > Emulator and then and then uncheck Launch into tool window
For windows user Go to Settings >Tools > Emulator and then and then uncheck Launch into tool window
Note : Before Doing this activity close all running Emulators and if needed restart the Android studio after changing the Emulator settings

How can I debug Flutter apps on Chrome and have Android Studio stop at breakpoints?

If I press Ctrl+Enter, Shift+F9 or Shift+F10, or go to Run > Run 'main.dart' or Run > Debug 'main.dart', Android Studio tries to run or debug my app on my android device, if connected, or else reports 'No connected devices...'. Debug behaves as expected, stopping at breakpoints.
('No connected devices' is already strange, as flutter devices returns that both android and Chrome devices are connected and flutter doctor returns no issues. Flutter web is enabled.)
If I go to terminal in Android Studio, I can execute flutter run -d chrome, and the app runs in 'debug mode' on Chrome. This debug mode, however, does not stop at breakpoints or behave in any obviously different way to if the app were simply run.
How can I run flutter apps on Chrome and have Android Studio stop at breakpoints?
To ensure that Android Studio is able to see the Chrome to run the project as a web app, you can select the Chrome from the list of devices dropdown - highlighted in a rectangle in the picture. You can also run the app in debug mode by clicking on the shortcut button from the toolbar - highlighted in circle.
I'm currently running Flutter plugin version 71.2.3 and the breakpoints works as expected. Dart plugin is on version 213.7433

How to view Flutter debug console output for a release version of the app?

Using print() to log messages works in debug mode and I can see output in debug console of VSCode or in terminal. How can I get those with release build ? I have seen release build producing such logs but not sure how to get those.
Run
$ flutter logs
in terminal with terminal opened in a flutter project directory, connect phone with computer and use the release version of the app on phone to see logs similar to the debug version shows.
Edit: Not sure if this works for iOS.