How to clear Flutter's Build cache?

2020-05-24 20:46发布

There seems to be a problem with flutter's build.

I always need to perform RUN > Flutter Full Restart everytime I run the app to an emulator or device.

Otherwise, the app loads a scaffold body which my code had from 2 weeks ago when I first started coding it.

Here's the current source on pastebin

children: <Widget>[
          new Opacity(
              opacity: loader_visible ? 1.0 : 0.0,
              child:
              new Container(
                  padding: const EdgeInsets.all(32.0),
                  child: new CircularProgressIndicator()
              )
          ),

while here is the resulting render tree: while here is the resulting render tree

I'm guessing flutter has cached the old code and never bothered replacing it with the new one, but I am not sure how it's Hot Reload was implemented. Anyways, I don't think that it is necessary to load the old cache when we have already performed a full rebuild.

标签: dart flutter
6条回答
够拽才男人
2楼-- · 2020-05-24 21:07

I found a way to automate running the clean before you debug your code. (Warning, this runs everytime you hit the button, even for hot restart)

  1. First, find the Run > Edit Configurations Menu

  2. Click the External tool '+' icon under Before launch: External tool, Activate tool window.

  3. Run External Tool
  4. Configure it like so. Put the working directory as a directory in your project.

Edit Configurations. Configurations

Run External Tool Add Flutter Clean

查看更多
干净又极端
3楼-- · 2020-05-24 21:15

You can run flutter clean.

But that's most likely a problem with your IDE or similar, as flutter run creates a brand new apk. And hot reload push only modifications.

Try running your app using the command line flutter run and then press r or R for respectively hot-reload and full-reload.

查看更多
贼婆χ
4楼-- · 2020-05-24 21:18

There are basically 3 alternatives to cleaning everything that you could try:

  • flutter clean will delete the /build folder.
  • Manually delete the /build folder, which is essentially the same as flutter clean.
  • Or, as @Rémi Roudsselet pointed out: restart your IDE, as it might be caching some older error logs and locking everything up.
查看更多
5楼-- · 2020-05-24 21:21

If in android studio Tools->Flutter->Clean

enter image description here

查看更多
ゆ 、 Hurt°
6楼-- · 2020-05-24 21:21

Or you can delete the /build folder under your /app-project folder manually if you cannot run flutter command.

查看更多
地球回转人心会变
7楼-- · 2020-05-24 21:27

I tried flutter clean and that didn't work for me. Then I went to wipe the emulator's data and voila, the cached issue was gone. If you have Android Studio you can launch the AVD Manager by following this Create and Manage virtual machine. Otherwise you can wipe the emulator's data using the emulator.exe command line that's included in the android SDK. Simply follow this instructions here enter link description here.

查看更多
登录 后发表回答