Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Image.memory() loading animation with slow large files

I am fetching an image from the gallery and displaying it in my cropper with Image.memory(). But sometimes (with large files) it takes a few seconds for the image to show. I want to show a loading animation but how do I detect when it is loading or finished? There is no loadingBuilder like for Image.network(). Any ideas?

final XFile? image = await _picker.pickImage(source: ImageSource.gallery);

Image.memory(_imageToCrop!)
like image 311
AntEdote Avatar asked Sep 02 '25 03:09

AntEdote


1 Answers

Like Ankit Kumar Maurya said I studied the frameBuilder documentation and this solved my issue:

 Image.memory(
                      _imageToCrop!,
                      frameBuilder:
                          ((context, child, frame, wasSynchronouslyLoaded) {
                        if (wasSynchronouslyLoaded) return child;
                        return AnimatedSwitcher(
                          duration: const Duration(milliseconds: 200),
                          child: frame != null
                              ? child
                              : SizedBox(
                                height: 60,
                                width: 60,
                                child: CircularProgressIndicator(
                                    strokeWidth: 6),
                              ),
                        );
                      }),
                    ),
like image 59
AntEdote Avatar answered Sep 04 '25 23:09

AntEdote