Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode hot reload for Flutter does not work

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.

like image 392
Michael Brennan Avatar asked Jan 21 '19 05:01

Michael Brennan


People also ask

Does Flutter have hot reload?

Perform Hot Reload: Run your flutter editor from the app or using the command prompt. We can use hot reload in flutter debug mode. Once your flutter project has been created do some changes in your code and perform a hot reload. In windows, you can perform a hot reload using 'ctrl+\' or using the hot reload button.


2 Answers

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.

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.

like image 81
THE_BLESSED_MEDIUM Avatar answered Oct 18 '22 01:10

THE_BLESSED_MEDIUM


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

like image 27
sidnas Avatar answered Oct 18 '22 01:10

sidnas