Reputation: 34180
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.
Upvotes: 39
Views: 51738
Reputation: 253
it work for me in Android Studio Koala. Please remove shortcut for Manual Live Edit in Settings => Keymap => search "Manual Live Edit"
Upvotes: 0
Reputation: 1259
I constantly have similar problems when there are new unapplied Mac OS updates. You can disable auto-updates or install updates from incoming notifications.
Upvotes: -1
Reputation: 96
My issue was that I was running flutter run
from the Android Studio terminal instead of clicking the Play or Debug button to run my application.
Upvotes: 1
Reputation: 1985
A hot reload in android studio against vscode which is Ctrl+S is triggered by Save All or explicitly calling the hot reload
https://docs.flutter.dev/get-started/test-drive?tab=androidstudio
A workaround is to set Ctrl+S as the save all shortcut. Out of the box it's Ctrl+K, S, that's why you see other solution that is suggesting to reset your keymap to Intellij
Upvotes: 4
Reputation: 225
In my case, when I used the VSCode keymap plugin, the hot reloading on save did`nt work. After I changed the keymap to IntelliJ keymap, the hot reloading on save worked properly.
Upvotes: 3
Reputation: 679
In my case, hot reload failed due to insufficient storage space on the emulator. I didn't get an error in the console until I stopped and tried to re-run the project. To get hot reload working in my case, I had to stop the emulator, and increase the storage capacity on the device, and re-run the project.
Upvotes: 0
Reputation: 567
Hot reload works only out of the main method. If your is inside the main method try to make a class of stateless or stateful widgets and pass the name as a parameter to runApp()
Upvotes: 0
Reputation: 813
In my case, it was just extracting the whole MaterialApp
into it's own stateless Widget
.
Before -
void main() {
runApp(MaterialApp(
home: Scaffold(
backgroundColor: Colors.teal,
body: SafeArea(
child: Container(
color: Colors.white,
child: Text("Helloo"),
height: 100,
width: 100,
margin: EdgeInsets.all(20),
)),
),
));
}
After -
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.teal,
body: SafeArea(
child: Container(
color: Colors.white,
child: Text("Helloo"),
height: 100,
width: 100,
margin: EdgeInsets.all(20),
)),
),
);
}
}
Even VS Code complains if you are just defining your whole app inside main function.
Solved! Enjoy :)
Upvotes: 7
Reputation: 5256
Hot reload stopped working suddenly in my project. Using Android Studio and Windows.
When moving files around, the Android Studio would refactor imports, which is neat. But it would use absolute imports (C://Users/Projects/.../file.dart) and that would break hot reload completely. Be careful when moving files.
Upvotes: 2
Reputation: 827
There are following steps to resovle this issue
Check the import package line it should be like
packages: your file
not file:///
use command flutter clean
then flutter pub get
in your terminal / command promp
NOTE: you have to use these command from your project root directory
Its work for me
Upvotes: 0
Reputation: 646
Encountered same issue with Flutter 1.22.6. But worked fine when I used Cmd+S
instead of Hot Reload (lightning) button
Upvotes: 0
Reputation: 3319
In my case i just deleted the old app from phone. Then run from Android Studio. Maybe i tried release app and don't delete after(can't remember exactly). In any case, it is solved!
Upvotes: 0
Reputation: 592
These might cause because of too many codes and assets. Simply delete the app from the emulator and rerun it again.
Upvotes: 0
Reputation: 2448
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';
Upvotes: 22
Reputation: 29
Put your code inside stateless of stateful widget. To make HOT RELOAD work code must be inside stateless of stateful widget.
Upvotes: 2
Reputation: 387
I am using VScode for flutter in Windows. Was facing same issue with hot reload. Updated Dart and Flutter package to latest version and luckily it started working.
Upvotes: 1
Reputation: 171
Upvotes: 0
Reputation: 962
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.
Upvotes: 76
Reputation: 1135
Wrap your code with a StatefulWidget
like shown in the code below.
This might be confusing when watching old tutorials because it used to work without it on an earlier Flutter Version.
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Demo Project"),
),
body: Center(child: new Text("Hello World!!!")),
);
}
}
Upvotes: 6
Reputation: 2982
How to use Flutter Hot Reload in a StatelessWidget inside Android Studio 3.6.2 and Flutter v1.12.13+hotfix.9 on Linux ... inside main.dart file:
Make sure in Android Studio > File > settings > Languages & Frameworks > Flutter > check "Perform hot reload on save"!!!
Use the code below -> change the 'Hello' -> save it -> see the hot reload result
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// StatelessWidget turns this class into a widget
Widget build(BuildContext context) {
return MaterialApp(
home: Text('Hello'),
);
}
}
Upvotes: 1
Reputation: 21
You have to save your changes you made in main.dart file. After that hot reload will work, on visual studio select auto-save option then it will work perfectly fine.
*Hot reload needs to save your files first.
Upvotes: 0
Reputation: 549
This works if all else fails: 1. Close Android Studio and the Simulators
Delete Android Studio by opening the Finder, click Applications, right click on Android Studio and click Move to Trash
Remove Android files: $ cd ~/Library/Android $ rm -fr * $ cd $ rm -fr .android
Remove Java https://www.java.com/en/download/help/mac_uninstall_java.xml
Install Java
Install and Launch Android Studio and accept the license agreements https://developer.android.com/studio/install
Upvotes: 0
Reputation: 106
If I'm not mistaken, hot reload calls the build method of your widget, as the change you made weren't made inside a build method, it didn't change anything in the screen.
Try changing the texting inside the MyWidget Build method and see if it works.
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text("Demo Project"),
),
body: new MyWidget(),
),
));
}
class MyWidget extends StatelessWidget {
const MyWidget({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(child: new Text("Hello World!!!"));
}
}
Upvotes: 5
Reputation: 10204
This is what you're looking for
In File -> Settings -> Keymap, you should assign some key shortcut for that to happen. Default it will be Ctrl+\
Upvotes: -5
Reputation: 1538
in the terminal, run
flutter doctor -v
flutter upgrade
Also, try File > Invalidate Caches / Restart...
from Android studio menu
Upvotes: 5
Reputation: 807
I had the same problem. To solve it you need to update flutter sdk.
Upvotes: 0