_This might come straight from observatory, in which case I can move._
I 鉂わ笍 the new "reload-on-save" feature, but I think the output emitted is pretty confusing:
Launching lib/main.dart on iPhone SE in debug mode...
Reloaded 0 of 466 libraries in 410ms.
Reloaded 0 of 466 libraries in 303ms.
I ask myself the following questions when reading this output:
I think it might be more friendly to either say:
"No libraries required reloading (0 of 466 in 303ms)."
"Reload successful but no libraries reload (...)"
etc. Again, I'm not 100% sure what this means :)
I'm reasonably sure that output also appears on Hot Reload from the command line, so this should be asked on the main Flutter repo.
The reason you're seeing so many 0 events could be that the changes you made didn't affect the current state of the running app. I could be mistaken though.
This output does come from Flutter. My guess is that there's nothing to reload (Dart Code doesn't reliably know when a reload is required or not, though if it's expensive to "do nothing" possibly we could try and skip the command for obvious cases where nothing has changed).
I think your suggested text is much better (assuming it's accurate - 300ms does seem a long time to do nothing) so worth raising against the flutter or SDK repos (I don't know how the code is split for these things).
Great, thanks. I'll move this over!
The reason you're seeing so many 0 events could be that the changes you made didn't affect the current state of the running app. I could be mistaken though.
It's also possible my save-detection is kind aggressive - any file saved will trigger it, since I don't know if I can reliably tell which files might affect it (for ex. if I only did Dart files, what if you have some resource file? I'm not familiar enough with hot reload/Flutter to know what the rules are).
To be honest, having a line of output on every single file save might be a bit spammy, so maybe this needs handling better anyway. Maybe it the hot reload was initiated by a save and starts "Reloaded 0 of" I should suppress the output?
Filed @ https://github.com/flutter/flutter/issues/13187.
Yeah, maybe it makes sense to suppress (or rewrite) "0 of " messages, but I'll wait and see what the folks at https://github.com/flutter/flutter/issues/13187 say. In this particular case, the files I were modifying were not reachable from lib/main.dart. I don't know if IntelliJ handles this differently.
/cc @devoncarew
Yup, this text comes from flutter_tools.
Definitely agree that the text Reloaded 0 of 466 libraries in 410ms. is too mechanical and could use clarifying for the n=0 case.
IntelliJ works a bit differently wrt saving files. It auto-saves changes, and cmd-s is mapped to 'save all', not file save. Possibility because of this, we found that users developed a mental model of 'cmd-s == reload'. The IntelliJ plugin did have more change detection in terms of sets of changes that wouldn't effect the running app - we wouldn't reload in those cases. This ended up being too unpredictable for users - sometimes cmd-s would reload, and sometimes it wouldn't. We ended up simplifying to having cmd-s always reload.
Sounds like Dart Code probably isn't too dissimilar to IntelliJ then, though now I'm thinking if you turn auto-save on in Code you'll get super-spammy reloading. I'll add a case to check that. I'm not sure how to best fix that though - I can't go re-binding the save key and even if I can tell the difference between auto/manual save, I can't skip it since the user might be wanting the reload.
@devoncarew Is there any possibility of making this message not just go to stdout so I can handle it better (eg. show it on the status bar or something) to reduce the spam?
though now I'm thinking if you turn auto-save on in Code you'll get super-spammy reloading
If it is an issue, you could just not reload on save if they have auto-save enabled. We are able to detect the difference between an auto-save and a manual one in IntelliJ. Very early UX reviews of reload-on-save did turn up that you really only want to reload on some explicit user action. So reloading the app just because you switched apps and IntelliJ lost focus (and triggered an auto-save), was unexpected and not desired :)
Is there any possibility of making this message not just go to stdout so I can handle it better (eg. show it on the status bar or something) to reduce the spam?
I think its useful for the user to know when a reload happened, and some bits of data about the reload. IntelliJ actually clears the console between reloads in order to help bookend each reload.
So, instead of trying to regex out the message in order to reduce console spam, I think I'd first look at ways of making reload-on-save less spammy. Not 100% clear when those would be occurring, but if saves are happening very frequently together - on the same file or multiple - you could debounce that a bit with a few hundred ms delay.
If it is an issue, you could just not reload on save if they have auto-save enabled. We are able to detect the difference between an auto-save and a manual one in IntelliJ. Very early UX reviews of reload-on-save did turn up that you really only want to reload on some explicit user action.
What happens if the user makes a change; auto-save fires, then the user wants to hot reload? In Code, I don't think hitting Ctrl+S would do anything (it'd bail out early because there's nothing to save). That could also be frustrating :(
I also encountered a similar problem.The problem I finally found it is that the path has two slashes when importing, like below:
import 'src/decorate_box//box.dart';
change to import 'src/decorate_box/box.dart';
then it's working.
@HengCC I don't know if it matches your issue, but I found some strange behaviour with two slashes which I've opened an issue about at https://github.com/flutter/flutter/issues/29909.
Use IDEA to import files automatically, and find this line in the header
import 'file:///E:/enzo/code/flutter/yd_xuantao/lib/ui/page/profile/my_team_page/my_team_page.dart';
Change code to
import 'package:ydxuantao/ui/page/profile/my_team_page/my_team_page.dart';
And then the hot reload works, I found the problem caused by IDEA for 2 hours
Use IDEA to import files automatically, and find this line in the header
import 'file:///E:/enzo/code/flutter/yd_xuantao/lib/ui/page/profile/my_team_page/my_team_page.dart';Change code to
import 'package:ydxuantao/ui/page/profile/my_team_page/my_team_page.dart';And then the hot reload works, I found the problem caused by IDEA for 2 hours
I spend a half-day to find out "why flutter hot reload not working?".
only you know why?
after change imports, we need to clean flutter caches.
it worked very well.
Thanks Men.
Use IDEA to import files automatically, and find this line in the header
import 'file:///E:/enzo/code/flutter/yd_xuantao/lib/ui/page/profile/my_team_page/my_team_page.dart';Change code to
import 'package:ydxuantao/ui/page/profile/my_team_page/my_team_page.dart';
And then the hot reload works, I found the problem caused by IDEA for 2 hoursI spend a half-day to find out "why flutter hot reload not working?".
only you know why?after change imports, we need to clean flutter caches.
it worked very well.Thanks Men.
I guess that after reading from the local file, the flutter reads the cache from memory every time, so no matter how the file changes, it cannot hot reload
Use IDEA to import files automatically, and find this line in the header
import 'file:///E:/enzo/code/flutter/yd_xuantao/lib/ui/page/profile/my_team_page/my_team_page.dart';Change code to
import 'package:ydxuantao/ui/page/profile/my_team_page/my_team_page.dart';
And then the hot reload works, I found the problem caused by IDEA for 2 hoursI spend a half-day to find out "why flutter hot reload not working?".
only you know why?
after change imports, we need to clean flutter caches.
it worked very well.
Thanks Men.I guess that after reading from the local file, the flutter reads the cache from memory every time, so no matter how the file changes, it cannot hot reload
After Flutter Clean, Hot Reload work.
Use IDEA to import files automatically, and find this line in the header
import 'file:///E:/enzo/code/flutter/yd_xuantao/lib/ui/page/profile/my_team_page/my_team_page.dart';Change code to
import 'package:ydxuantao/ui/page/profile/my_team_page/my_team_page.dart';And then the hot reload works, I found the problem caused by IDEA for 2 hours
Where to fix it
Use IDEA to import files automatically, and find this line in the header
import 'file:///E:/enzo/code/flutter/yd_xuantao/lib/ui/page/profile/my_team_page/my_team_page.dart';Change code to
import 'package:ydxuantao/ui/page/profile/my_team_page/my_team_page.dart';
And then the hot reload works, I found the problem caused by IDEA for 2 hoursWhere to fix it
At the very top of your main.dart there is an import statement.
Most helpful comment
Use IDEA to import files automatically, and find this line in the header
Change code to
import 'package:ydxuantao/ui/page/profile/my_team_page/my_team_page.dart';And then the hot reload works, I found the problem caused by IDEA for 2 hours