flutter_svg icon indicating copy to clipboard operation
flutter_svg copied to clipboard

No response from precachePicture when restart app

Open Adrek opened this issue 3 years ago • 4 comments

Hello everyone, I will appreciate your help on how the precachePicture works.

I have a future function that waits for the preload of an SVG. It then performs another action like sending to a route containing the svg for example. But something happens that I can't understand.

Future<void> _preloadImages() async {
  await precachePicture(
      ExactAssetPicture(
          SvgPicture.svgStringDecoderBuilder, 'assets/icons/car_driving.svg'),
      context);

  // The first time, the next line is executed correctly.
  // But, when I press Restart app, the following line is not executed. The app is waiting for the future.
  print('Go to page that contains svg key');
}
  • When the app is stopped, I start debugging with F5 in VSCode. The precachePicture function preloads the SVG and executes the next line that sends to another page and displays the widget with the svg. So far so good.

  • With the application running, I press Restart in VSCode dato, the precachePicture function is called and it stays there. I get no response from the future, so the next line is not executed. Why is this behavior? It only fixes itself if I stop the app and run it again.

I know that in the build release this would not be a problem because the user does not have an option to restart. However, in the development environment it is frustrating to be stopping the application and running again.

Thank you very much in advance

Adrek avatar Mar 10 '22 00:03 Adrek

Hmm. Perhaps we need to clear the cache when reassemble is called.

dnfield avatar Mar 10 '22 17:03 dnfield

I don't have a lot of time to do a test case for this - can yo do a small test that calls PicturerProvider.cache.clear() when reassemble is called? You can see an example of how to listen to reassemble in https://stackoverflow.com/questions/55281077/how-to-detect-hot-reload-inside-the-code-of-a-flutter-app

I'm relatively confident that that is the problem. If you can verify, there's an easy fix for it.

dnfield avatar Mar 13 '22 05:03 dnfield

I don't have a lot of time to do a test case for this - can yo do a small test that calls PicturerProvider.cache.clear() when reassemble is called? You can see an example of how to listen to reassemble in https://stackoverflow.com/questions/55281077/how-to-detect-hot-reload-inside-the-code-of-a-flutter-app

I'm relatively confident that that is the problem. If you can verify, there's an easy fix for it.

Thank you very much for answering.

I did it according to the link you sent but reassemble is called when it is hot reload but not in hot restart.

For another way, I'm calling PicturerProvider.cache.clear() and it doesn't fix the problem when I do Hot restart. Is there another way to attack this issue? Thank you very much for your help.

Adrek avatar Mar 21 '22 14:03 Adrek

Cant catch exception or any response from precache. Is there any solution?