bluefireteam / photo_view

📸 Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.
MIT License
1.91k stars 548 forks source link

[BUG]Wrapping PhotoViewGallery.builder inside GestureDetector, make GestureDetector onLongPress not working on iOS #358

Open anchao-lu opened 4 years ago

anchao-lu commented 4 years ago

Describe the bug 've wrapped the PhotoViewGallery inside an GestureDetector. If i longPress on a random position on the screen, the onLongPress event of the upper GestureDetector never fired on iOS device, but Android is ok.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
              top: 0,
              left: 0,
              bottom: 0,
              right: 0,
              child: GestureDetector(
                child: Container(
                    color: Colors.black,
                    child: PhotoViewGallery.builder(
                      scrollPhysics: const BouncingScrollPhysics(),
                      builder: (BuildContext context, int index) {
                        return PhotoViewGalleryPageOptions(
                          imageProvider: NetworkImage(widget.images[index]),
                          heroAttributes: widget.heroTag != null
                              ? PhotoViewHeroAttributes(tag: widget.heroTag)
                              : null,
                        );
                      },
                      itemCount: widget.images?.length ?? 0,
                      loadingBuilder: (context, event) {
                        return Center(
                          child: CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation(MAIN_COLOR),
                            value: (event?.cumulativeBytesLoaded ?? 0) /
                                (event?.expectedTotalBytes ?? 1),
                          ),
                        );
                      },
                      backgroundDecoration: null,
                      pageController: _controller,
                      enableRotation: true,
                      onPageChanged: (index) {
                        setState(() {
                          _currentIndex = index;
                        });
                      },
                    )),
                onTap: () {
                  Navigator.of(context).pop();
                },
                onLongPress: () {
                  print('this is not working on iOS device');
                },
              )),
          Positioned(
            top: MediaQuery.of(context).padding.top + 30,
            width: MediaQuery.of(context).size.width,
            child: Center(
              child: Text("${_currentIndex + 1}/${widget.images?.length ?? 0}",
                  style: TextStyle(color: Colors.white, fontSize: 16)),
            ),
          ),
          Positioned(
            right: 10,
            top: MediaQuery.of(context).padding.top + 15,
            child: IconButton(
              icon: Icon(
                Icons.close,
                color: MAIN_COLOR,
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ),
          Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                width: widget.images.length >= 6
                    ? 200
                    : widget.images.length < 3
                        ? 50
                        : 100,
                height: widget.images.length == 1 ? 0 : 50,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: List.generate(
                    widget.images.length,
                    (i) => GestureDetector(
                      child: CircleAvatar(
                        radius: 5.0,
                        backgroundColor:
                            _currentIndex == i ? MAIN_COLOR : Colors.grey,
                      ),
                    ),
                  ).toList(),
                ),
              ))
        ],
      ),
    );
  }
anchao-lu commented 4 years ago

Describe the bug 've wrapped the PhotoViewGallery inside an GestureDetector. If i longPress on a random position on the screen, the onLongPress event of the upper GestureDetector never fired on iOS device, but Android is ok.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
              top: 0,
              left: 0,
              bottom: 0,
              right: 0,
              child: GestureDetector(
                child: Container(
                    color: Colors.black,
                    child: PhotoViewGallery.builder(
                      scrollPhysics: const BouncingScrollPhysics(),
                      builder: (BuildContext context, int index) {
                        return PhotoViewGalleryPageOptions(
                          imageProvider: NetworkImage(widget.images[index]),
                          heroAttributes: widget.heroTag != null
                              ? PhotoViewHeroAttributes(tag: widget.heroTag)
                              : null,
                        );
                      },
                      itemCount: widget.images?.length ?? 0,
                      loadingBuilder: (context, event) {
                        return Center(
                          child: CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation(MAIN_COLOR),
                            value: (event?.cumulativeBytesLoaded ?? 0) /
                                (event?.expectedTotalBytes ?? 1),
                          ),
                        );
                      },
                      backgroundDecoration: null,
                      pageController: _controller,
                      enableRotation: true,
                      onPageChanged: (index) {
                        setState(() {
                          _currentIndex = index;
                        });
                      },
                    )),
                onTap: () {
                  Navigator.of(context).pop();
                },
                onLongPress: () {
                  print('this is not working on iOS device');
                },
              )),
          Positioned(
            top: MediaQuery.of(context).padding.top + 30,
            width: MediaQuery.of(context).size.width,
            child: Center(
              child: Text("${_currentIndex + 1}/${widget.images?.length ?? 0}",
                  style: TextStyle(color: Colors.white, fontSize: 16)),
            ),
          ),
          Positioned(
            right: 10,
            top: MediaQuery.of(context).padding.top + 15,
            child: IconButton(
              icon: Icon(
                Icons.close,
                color: MAIN_COLOR,
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ),
          Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                width: widget.images.length >= 6
                    ? 200
                    : widget.images.length < 3
                        ? 50
                        : 100,
                height: widget.images.length == 1 ? 0 : 50,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: List.generate(
                    widget.images.length,
                    (i) => GestureDetector(
                      child: CircleAvatar(
                        radius: 5.0,
                        backgroundColor:
                            _currentIndex == i ? MAIN_COLOR : Colors.grey,
                      ),
                    ),
                  ).toList(),
                ),
              ))
        ],
      ),
    );
  }

on iOS Simulator is ok

anchao-lu commented 4 years ago

Describe the bug Wrapped the PhotoViewGallery inside an GestureDetector. If i longPress on a random position on the screen, the onLongPress event of the upper GestureDetector never fired on iOS device, but Android is ok.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
              top: 0,
              left: 0,
              bottom: 0,
              right: 0,
              child: GestureDetector(
                child: Container(
                    color: Colors.black,
                    child: PhotoViewGallery.builder(
                      scrollPhysics: const BouncingScrollPhysics(),
                      builder: (BuildContext context, int index) {
                        return PhotoViewGalleryPageOptions(
                          imageProvider: NetworkImage(widget.images[index]),
                          heroAttributes: widget.heroTag != null
                              ? PhotoViewHeroAttributes(tag: widget.heroTag)
                              : null,
                        );
                      },
                      itemCount: widget.images?.length ?? 0,
                      loadingBuilder: (context, event) {
                        return Center(
                          child: CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation(MAIN_COLOR),
                            value: (event?.cumulativeBytesLoaded ?? 0) /
                                (event?.expectedTotalBytes ?? 1),
                          ),
                        );
                      },
                      backgroundDecoration: null,
                      pageController: _controller,
                      enableRotation: true,
                      onPageChanged: (index) {
                        setState(() {
                          _currentIndex = index;
                        });
                      },
                    )),
                onTap: () {
                  Navigator.of(context).pop();
                },
                onLongPress: () {
                  print('this is not working on iOS device');
                },
              )),
          Positioned(
            top: MediaQuery.of(context).padding.top + 30,
            width: MediaQuery.of(context).size.width,
            child: Center(
              child: Text("${_currentIndex + 1}/${widget.images?.length ?? 0}",
                  style: TextStyle(color: Colors.white, fontSize: 16)),
            ),
          ),
          Positioned(
            right: 10,
            top: MediaQuery.of(context).padding.top + 15,
            child: IconButton(
              icon: Icon(
                Icons.close,
                color: MAIN_COLOR,
              ),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ),
          Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                width: widget.images.length >= 6
                    ? 200
                    : widget.images.length < 3
                        ? 50
                        : 100,
                height: widget.images.length == 1 ? 0 : 50,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: List.generate(
                    widget.images.length,
                    (i) => GestureDetector(
                      child: CircleAvatar(
                        radius: 5.0,
                        backgroundColor:
                            _currentIndex == i ? MAIN_COLOR : Colors.grey,
                      ),
                    ),
                  ).toList(),
                ),
              ))
        ],
      ),
    );
  }

on iOS Simulator is ok

Hynsen commented 3 years ago

I found the same problem