VSCode hot reload for Flutter does not work
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.
if you are still facing this issue
open VS code then go to:
- File > Preferences > Settings
- in the search field type "Hot Reload"
- you will see "Flutter Hot Reload On Save" and three options are there
- the default is "manual" so change it to "always"
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