Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Hot reloading not working in android studio(mac)

Tags:

While working on mac machine I found that hot reloading not working in Android Studio. I don't know what's wrong :)

Here is the code which not reloading(I am changing the Hello world text to Flutter Sample text)

import 'package:flutter/material.dart';  void main() {   runApp(new MaterialApp(     home: new Scaffold(       appBar: new AppBar(         title: new Text("Demo Project"),       ),       body: Center(child: new Text("Hello World!!!")),     ),   )); } 

Please see this below video with the link https://www.dropbox.com/s/e7viujcgv8w0mtr/hot_reload.mp4?dl=0

This not stop my development, But I am concerned why it is happening.

like image 770
Jitesh Mohite Avatar asked Jul 20 '19 18:07

Jitesh Mohite


People also ask

Does Flutter have hot reload?

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. In mac devices, you perform a hot reload using 'cmd+s'. If you are working in the command prompt using flutter run enter 'r' to run.

What is the difference between hot restart and hot reload?

Hot restart takes more time than hot reload, and it destroys or rebuilds the state value and rebuilds it to the default. The app widget tree is completely rebuilt with a newly typed code. This takes about 23-30 seconds compared with the default app restart time.


2 Answers

Flutter Documentation says "Hot reload loads code changes into the VM and re-builds the widget tree, preserving the app state; it doesn’t rerun main() or initState()"

So, it looks like if the app logic resides outside the main method, then Hot Reloading works. Try to refactor your app like below and then do Restart (green button). Any subsequent changes you make, will be HOT RELOADED when saved.

void main() {   runApp(MyApp()); }  class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       home: new Scaffold(         appBar: new AppBar(           title: new Text("Demo Project"),         ),         body: Center(child: new Text("Hello World!!!")),       ),     );   } } 

UPDATE: Hot Reload will not work if you are adding new assets (like images, or medial files). In those cases you will have to restart the App.

like image 167
Invin Avatar answered Oct 05 '22 18:10

Invin


Try This

The solution on GitHub Reloaded 0 of NNN libraries in Xms

Android Studio uses IDEA to import files automatically, Like this

import 'file///F:/flutter_project/lib/home_page.dart'; 

Change it to

import 'package:flutter_project/home_page.dart'; 
like image 26
vishwajit76 Avatar answered Oct 05 '22 19:10

vishwajit76