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.
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.
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.
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.
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With