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

Loop gallery infinity #378

Open
chreck opened this issue Nov 30, 2020 · 6 comments · May be fixed by #543
Open

Loop gallery infinity #378

chreck opened this issue Nov 30, 2020 · 6 comments · May be fixed by #543
Labels
enhancement New feature or request P1

Comments

@chreck
Copy link

chreck commented Nov 30, 2020

Is your feature request related to a problem? Please describe.
Normally an image gallery can be paged back and forth. Showing the images in a loop is very common.

Describe the solution you'd like
The PageView does support this. See example https://dartpad.dartlang.org/8c9075a0896138df116715ea36186506 or https://gist.github.com/Blasanka/a870803bb57bb57caf7eea11698e5a19. You just need to remove the itemCount parameter and make that not required anymore. I tried it out on my end but with no luck so far.

Describe alternatives you've considered
I could not found any other way.

@renancaraujo renancaraujo added the enhancement New feature or request label Dec 2, 2020
@renancaraujo renancaraujo added this to To do in Feature impl via automation Dec 2, 2020
@sstadtl
Copy link

sstadtl commented Jan 18, 2021

i accomplished the same by:

  • adding first element again as last and last as first
  • start on page 1
  • onpagechange jump on '0' and 'length-2'
class PhotoViewerFiles extends StatefulWidget {
  final List<File> bilder;

  const PhotoViewerFiles({Key key, this.bilder}) : super(key: key);
  @override
  _PhotoViewerFilesState createState() => _PhotoViewerFilesState();
}

class _PhotoViewerFilesState extends State<PhotoViewerFiles> {
  Color backcolor = Colors.black; //Colors.transparent;
  PageController _pageController;
  List<File> mybilder;
  @override
  void initState() {
    super.initState();
    _pageController = PageController(
      initialPage: 1,
    );
    mybilder = [widget.bilder.last, ...widget.bilder, widget.bilder.first];

  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  void onpageChanged(idx) {
    debugPrint('onpageChanged$idx');
    if (idx == 0) {
      Future.delayed(Duration(milliseconds: 350), () {
        _pageController.jumpToPage(mybilder.length - 2);
      });
} else if (idx == (mybilder.length - 1)) {
      Future.delayed(Duration(milliseconds: 350), () {
        _pageController.jumpToPage(1);
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: backcolor,
        child: Stack(
          children: [
            Hero(
              tag: widget.bilder[0].path,
              child: PhotoViewGallery.builder(
                itemCount: mybilder.length,
                onPageChanged: onpageChanged,
                pageController: _pageController,

@Albert221
Copy link

+1, I think this would be a really handy feature and it seems like it's not that hard to implement. Thanks for your package!

@rulila52

This comment was marked as off-topic.

2 similar comments
@ericaig

This comment was marked as off-topic.

@hqt98

This comment was marked as off-topic.

@thu-san

This comment was marked as off-topic.

TesteurManiak added a commit to TesteurManiak/photo_view that referenced this issue Oct 13, 2023
@TesteurManiak TesteurManiak linked a pull request Oct 13, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1
Projects
Feature impl
  
To do
Development

Successfully merging a pull request may close this issue.

8 participants