VS code not hot reloading for Flutter - flutter

Hi i am using Visual Studio with flutter and i am having issues with the hot reload and hot restart.
1.For hot reload its not working at all, on the bottom right corner it shows "syncing files with android x86..." but after a second it disappears but nothing changes on the emulator.
2. For hot restart its taking alot of time on the first attempt but for the rest of the time it works fine.
-
What i tried to fix it:
Looked on stackOverflow and github for similar issues and tried their fixes which were:
- Deleting and downloading a newer version of VS code
- Downgrading to VS code 3.1.
- Switching to master channel
Nothing seemed to fix the issue so any help would be appreciated.

Run flutter doctor to fix the issue. If it can't detect the emulator, restart your VS Code and your emulator.

Related

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

Breakpoints not working with Flutter in Android Studio

I can set breakpoints, but when I run in Debug mode the breakpoint's icon change with this:
I think that the problem is the new version of Flutter plugin in Android Studio, but I'm not sure. How to fix this?
What I've tried:
flutter clean
android studio cache clean and restart
Upgrade to the latest version of the flutter plugin 65.1.3 solved my problem.
https://plugins.jetbrains.com/plugin/9212-flutter/versions
need to roll back the version of the flutter plugin to 64.1.2.
https://plugins.jetbrains.com/plugin/9212-flutter/versions
Confirmed: plug-in was one thing.
The other problem is that IntelliJ (same for Android Studio) distinguish between:
import '../../viewmodel/**m**essages
import '../../viewmodel/**M**essages
Compiling, running, Dart analysis ... everything's fine. However, breakpoints don't work!
To be more precise: some breakpoints don't work, only in some files!
Tip: If a breakpoint does not work, remove all imports in the file. Click the bulb to get suggestions - and you will see the duplicate imports.
See wrong imports
Btw.: I am on Windows. And the file system does not distinguish between upper and lower case filenames.
Faced to this issue today as well: looks like for me the solution was to update Flutter / Dart SDK and their Plugins for Android Studio.
Some users report the problem is linked to the Chrom Version >=100 due to API change, but on my side it was not working with Edge as well.
After update problem has gone
There is indeed also an issue with Chrome Version >=100. Running flutter upgrade (to flutter 2.10.5) fixed this for me as described here

I'm not able to run any flutter app on my emulator (VSC & Android Studio)

So basically the problem is that I created a new flutter app, and the I opened the emulator(from android studio), and I clicked on run.
I had multiple problems that were related to heap memory and such, but I managed to solved most of then using all kind of methods from the internet.
I even deleted and installed Java and android studio multiple times, I changed the Enviromental Variables as the Internet suggested, but now, the current error that I get is this:
The Error Image
my flutter doctor -v:
flutter doctor -v image
I'm about to lose my mind, I'm on this issuse for a few weeks. please help me fix it
after your seggestion to add "gradle.properties" and adding "org.gradle.jvmargs=-Xmx1024m" to it (without the " "):
after
Perhaps you shoud add a line at end of file gradle.properties org.gradle.jvmargs=-Xmx1024m then clean the project, also validate cache and restart the android studio. It should works then.

Flutter: Hot Reload gets stuck in Visual Studio Code

UPDATE:
I tried with another clean new project. Hot reload works fine.
Every time I perform a hot reload on my VS Code, the hot reload gets stuck with the following message. Anyone knows the problem?
These are the things that I have done.
Terminal: Ran flutter doctor -- (everything ok, except a warning sign of a little bit outdated Xcode. I'm using Xcode 11.1.0)
Restarted VS
Restarted the entire machine
Running on both simulator and physical iPad
These are my specs:
Macbook Pro Early 2015
macOS Mojave
VS Code 1.52.1 (latest)
Flutter extension v3.18.1 (latest)
Dart v3.18.1 (latest)
Xcode 11.1.0 (not latest)
Debug console:
Launching lib/main.dart on iPad Pro (9.7-inch) in debug mode...
lib/main.dart:1
Xcode build done. 82.4s
Connecting to VM Service at ws://127.0.0.1:51095/_Dfl55VaXyE=/ws
if you are using Listview.builder or Grideview.builder then
comment it out or remove that code block.
sometimes it happens because of the unbounded height problem of
listview.builder and hot reload get stuck and fail to compile the
code.
I was try open DevTools in the browser and press Hot reload button and it's working!
Not sure which Flutter version you were using but you could be running into a case of https://github.com/flutter/flutter/issues/84347 which is related to isolates getting somehow stuck during hot reload.
I don't know the audioplayers library but I assume it uses an isolate in the background.
Delete the emulator and run flutter clean from the terminal.
Then create the emulator again and it will fix the issue.
Run flutter clean and run your project again and see if that solves the problem.

The refactoring option is gone after dart last update, what can I do, I tried restarting and uninstalled Visual Studio Code but nothing happened

Click on the image description.
Worked for me on beta as well. It's a bit less cutting edge than dev so might be better for some uses.
flutter channel beta
flutter upgrade
Also found out that turning off the previewLSP setting in the VSCode Dart & Flutter extension settings turns the refactoring menu back on. There seems to be a disagreement between LSP mode and refactoring that is fixed in later versions. If you don't want to upgrade you can try turning that setting off and then restarting VSCode.
Run flutter doctor, if flutter and dart are up to date then try switching to a different flutter channel and update flutter and dart again. It worked for me recently.
Try switch to dev channel,
flutter channel dev
flutter upgrade
I sugest to re-install the flutter plugin for VSCode (wich includes dart). See if it helps.