Reputation: 848
I'm on VSCode right now working on my flutter application when hot reload just stops working, right in the middle of my development. I have absolutely no idea why this happens, I had no issue with this before at all in the past. If it helps anyone, I'm working on the second page of my app, which you get to via a route on the first page. Is this why hot reload isn't working? If it isn't can someone tell me why it doesn't work? This is really annoying and hindering progress on my app. Thanks!
Restarting my computer, and restarting the debugging. I'm on a Macbook Pro 2015 running macOS Mojave Version 10.14.2 if that helps.
There isn't really any code to show, it's not code related. It's VSCode or Flutter.
I expect the hot reload to work, but it doesn't.
Upvotes: 57
Views: 78879
Reputation: 359
if you are still facing this issue
open VS code then go to:
Update - 12/Jun/2022 : instead of "always" the option now is = "All"
Upvotes: 32
Reputation: 6823
Upvotes: 0
Reputation: 1
In VS Code: File > Auto Save Auto save can solve this problem. When I used Ctrl+F5, I saw in vs code that it works, but nothings changed on the screen of emulator. I click on the File and then Auto save. After that my problem was solved. I tried the other solutions that other people wrote, but they didn't work for me. Only one person said it. Thanks him.
Upvotes: 0
Reputation: 11
Try the following things
Upvotes: 1
Reputation: 251
try killing dart from terminal
by typing killall -9 dart
then: 1- close vscode
2- re-open vscode (it may crash in the first run so reopen it again)
3- run flutter clean
4- run flutter pub get
5- run flutter run
this will fix the issue
Upvotes: 0
Reputation: 472
Solution is :
Click on File
> Preferences
> Settings
Search for "Hot Reload"
Click on Flutter Hot Reload On Save
and choose always
after that Click on File
and Click on Autosave
.
Upvotes: 0
Reputation: 1
May be you have changed the Keyboard shortcuts for hot reloading , kindly check if it is...
Upvotes: 0
Reputation: 43
try Ctrl + S , when I press Ctrl + S it's automatically doing hot reload
Upvotes: -3
Reputation: 81
Quoting here the answer of sidnas
I have noticed that hot reload is not working if you in runApp directly pass in MaterialApp. If separate core widget is created than everything works properly.
Working example:
void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text('Hot reload works!!')), ), ); } }
Not working:
void main() => runApp(MaterialApp( home: Scaffold( appBar: AppBar(title: Text('Hot reload not working')), ), ));
The reason why the second snippet prevents the hot reload from working is because the "main" only runs once and the hot reload doesn't run the main. So to make it work, you have to separate the MaterialApp to a different widget.
Upvotes: 8
Reputation: 585
I have noticed that hot reload is not working if you in runApp
directly pass in MaterialApp
. If separate core widget is created than everything works properly.
Working example:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Hot reload works!!')),
),
);
}
}
Not working:
void main() => runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Hot reload not working')),
),
));
Also don't forget to enable hot reload on save: https://stackoverflow.com/a/67132314/4990406
Upvotes: 55
Reputation: 11
Work for me:
Upvotes: 1
Reputation: 3689
For those who are using MAC.
I am using mac, and I handled this through by quitting first the emulator and VS Code and then restarting the computer.
It should be kept in mind that when you use stateless or stateful widget then you can get the feature of hot reload.
By pressing command+s it will save the file and will perform hot reload automatically.
Upvotes: 2
Reputation: 331
Make sure you don't have this type of imports I was going crazy and deleting them fixed the hot reload, check all your files, I found this answer in github: https://github.com/flutter/flutter/issues/49744
import file:///C:/Users/.../.../< App Name >/lib/filename.dart
Upvotes: -1
Reputation: 97
For VS Code Go to File>Autosave Make sure you have "check" Autosave.
Upvotes: 8
Reputation: 21
If you're implementing your MaterialApp in main.dart will cause this issue, the best practice is to separate out another dart file, then refer from main.dart.
Upvotes: 2
Reputation: 8656
Here are the official documented cases where hot reload wont work:
debug console
to be surereference: Hot Reload
Upvotes: 1
Reputation: 311
For me on the latest VS studio, pressing CRTL+s does the hot reload nicely for me. kinda a habbit from other IDE's.
Upvotes: 4
Reputation: 4450
I had the same problem in VS code. Here is how I solved it :
I was using style
property for Text
from an external file. I found that change in external file doesn't reflect in hot reload.
Text(
AppStrings.giveFeedbackPageText,
style: AppStyles.bodyText,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
So I had to use TextStyle
from that file instead of an external file, and it works! Dont know the reason. Probably the external style
needs to be inside a widget.
Another solution could be - separating home
from MaterialApp
into a separate widget.
Upvotes: -1
Reputation: 3002
with VS Code(v1.44.1), Android Studio(v3.6.2), Flutter v1.12.13+hotfix.9 on Linux
Android studio > at Startup window > configure > AVD manager > run one virtual device > confirm VS Code(v1.44.1) has your running virtual device shown in lower right corner
VS Code > Run(at top, next to Help) > Start debugging(F5) or Start without debugging(Ctrl + F5)
Save your Flutter code in VS Code Then the emulator should be triggered for hot reload
Upvotes: 0
Reputation: 1034
The hot reload doesn't work if you launch your app using f5 or select start debugging from the dropdown of debug .
But if you launch your app using Ctrl+f5 or select start without debugging from the dropdown of debug .
To solve the issue first close the running debugging session using Shift+f5.
Then click debug from the menu bar. Click Start without debugging.
Now The Hot reload works perfectly fine.
You can do the hot reload also using terminal. Just type: flutter run in the terminal and the app will be launched.
just press r in the terminal and hot reload will be initialized.
Upvotes: 53
Reputation: 126
I had the same problem. Currently I am using VSCode version 1.39.2.
For the hot reload to work you need to start debugging in VSCode.
As it says in the docs: "Only Flutter apps in debug mode can be hot reloaded." https://flutter.dev/docs/development/tools/hot-reload
You can find that option on the VSCode's top navigation inside Debug or with the shortcut F5.
You don't need to do flutter run on your terminal, nor even on VSCode, is just start debugging and it will launch lib/main.dart in debug mode.
If that doesn't solve the problem, try downgrading to the last version of VSCode.
Upvotes: 0
Reputation: 29
I found a way to force the hot reload in VS Code, which is very useful for those stuck in this situation: after the application is running, simply click on the debug option at the bottom of the VS Code editor whem the button is already named "Flutter" and, after choosing "flutter" again at the "Debug Configuraion" top floating window, you will be notified that the application is already being debugged, but the hot reload will occur.
Upvotes: 2
Reputation:
This appears to be a vscode issue in version 1.32.1 - see https://github.com/flutter/flutter/issues/29275 and https://github.com/Dart-Code/Dart-Code/issues/1518
In the meantime, you could revert to 1.31, wait for a fix in the next version, install the insiders version (which includes a fix), or could use 'flutter run' from the vscode terminal.
Upvotes: 1
Reputation: 179
For flutter hot reload problems that may be happening with your project,
It is a problem with your device, and not flutter or Android Studio
This happens when your logcat hangs up.
You might want to increase your buffer size.
To do this, go into your device or emulator:
Settings > Developer options (Ensure they are turned on),
Change the buffer size to a higher number.
Then run flutter run -v again
Upvotes: -1