Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在图片滑动的时候,是否能提供图片预加载功能 #24

Closed
hlj2722 opened this issue Jul 5, 2019 · 6 comments
Closed

在图片滑动的时候,是否能提供图片预加载功能 #24

hlj2722 opened this issue Jul 5, 2019 · 6 comments

Comments

@hlj2722
Copy link

hlj2722 commented Jul 5, 2019

No description provided.

@zmtzawqlp
Copy link
Member

什么叫图片滑动。。

@hlj2722
Copy link
Author

hlj2722 commented Jul 7, 2019

比如 example中的 PhotoViewDemo,在图片左右切换时,预先加载下一张图片

@zmtzawqlp zmtzawqlp added the enhancement New feature or request label Jul 19, 2019
@zmtzawqlp
Copy link
Member

你可以pageChanged时候,做如下操作,这样就相当于提前在内存中加载

               onPageChanged: (int index) {
                if (index > currentIndex) {
                  var nextOne = index + 1;
                  if (nextOne < widget.pics.length) {
                    var provider = ExtendedNetworkImageProvider(
                        widget.pics[nextOne].picUrl);
                    provider.resolve(createLocalImageConfiguration(context));
                  }
                }
                currentIndex = index;
                rebuildIndex.add(index);
              },

@zmtzawqlp zmtzawqlp removed the enhancement New feature or request label Jul 20, 2019
@hlj2722
Copy link
Author

hlj2722 commented Jul 27, 2019

好的,谢谢

@zmtzawqlp
Copy link
Member

https://api.flutter.dev/flutter/widgets/precacheImage.html 使用这个方法应该更好。原理是一样的

@user1121114685
Copy link

https://github.com/fluttercandies/extended_image/blob/master/example/lib/pages/simple/photo_view_demo.dart#L51

参考代码来了

` if (0 <= index && index < images.length) {
final String url = images[index];

  precacheImage(ExtendedNetworkImageProvider(url, cache: true), context);

  _cachedIndexes.add(index);
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants