On Jun 10, 2019, at 2:33 PM, Kristiyan Mitev <kom...@gmail.com> wrote:
This happens because (most probably) you're requesting the image when you are building the second page. You can pre-load it and keep a reference to it in some var 'cachedImage' or something like that.
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/fa780a1e-c846-479b-8f08-ca4d9ae05c84%40googlegroups.com.
Image image1;
void initState() {
image1 = Image.asset("assets/img/image.jpg");
super.initState();
}
@overridevoid didChangeDependencies() {
precacheImage(image1.image, context);
super.didChangeDependencies();
}
You can either pre-load the image in the first screen. Or you can use a stream builder on the second screen to show a circular loading image until the image renders. I do both in my app.
On Jun 10, 2019, at 2:33 PM, Kristiyan Mitev <kom...@gmail.com> wrote:
This happens because (most probably) you're requesting the image when you are building the second page. You can pre-load it and keep a reference to it in some var 'cachedImage' or something like that.--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/a1e4f4cc-8c9c-43e7-a111-70a3dc4c365c%40googlegroups.com.
package:flutter
Prefetches an image into the image cache.
Returns a [Future] that will complete when the first image yielded by the [ImageProvider] is available or failed to load.
If the image is later used by an [Image] or [BoxDecoration] or [FadeInImage], it will probably be loaded faster. The consumer of the image does not need to use the same [ImageProvider] instance. The [ImageCache] will find the image as long as both images share the same key.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/a1e4f4cc-8c9c-43e7-a111-70a3dc4c365c%40googlegroups.com.
Image imgbg_next_screen;
@override
void initState() {
// TODO: implement initState
imgbg_next_screen = Image.asset("assets/img/background.jpg");
super.initState();
}
@override
void didChangeDependencies() {
precacheImage(imgbg_next_screen.image, context);
super.didChangeDependencies();
}
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/a1e4f4cc-8c9c-43e7-a111-70a3dc4c365c%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/f23efe92-791f-4d7d-8c66-ccc585c3c112%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/f23efe92-791f-4d7d-8c66-ccc585c3c112%40googlegroups.com.
@override
void initState() {
super.initState();
SchedulerBinding.instance.addPostFrameCallback((_) {
// Quote from docs:
// Schedule a callback for the end of this frame.
//Does not request a new frame.
// This callback is run during a frame, just after the persistent frame callbacks (which is when the main rendering pipeline has been flushed). If a frame is in progress and post-frame callbacks haven't been executed yet, then the registered callback is still executed during the frame. Otherwise, the registered callback is executed during the next frame.
// The callbacks are executed in the order in which they have been added.
// Post-frame callbacks cannot be unregistered. They are called exactly once.
// this means:
// context is accessible here, also this will be called only once
// didChangeDependencies might be called multiple times.
// so it's a good idea to precache images here
// but it's doubtful that it'll work, because you need to precache
// images before the first frame is shown
});
}