Skip to content

PageView with viewportFraction < 1.0 - GestureDetector is not working properly #23873

Description

@rav3r

Internal: b/144873050

Hey, looks like there is a bug preventing gesture detection on right side of the widget inside page view with only one element and viewport fraction smaller than 1.0.

This is how my widget tree looks like:

column
  - page view
    - gesture detector
      - green container
    - gesture detector
      - blue container
  - page view
    - gesture detector
      - red container

screenshot from 2018-11-02 16-14-59

Top gesture detectors (green&blue widgets) work fine, I can click anywhere and I can see debug logs in console.
Bottom gesture detector (red widget) works fine only for left half of the widget. When I click on the right half then onTap callback is not fired. Looks like something is preventing gesture detector from getting input.

flutter doctor output:

[✓] Flutter (Channel beta, v0.9.4, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] Android Studio (version 3.1)
[!] IntelliJ IDEA Community Edition (version 2018.2)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected devices (1 available)

Source code to reproduce bug:

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Column(children: <Widget>[
        Expanded(
          child: ColorPages(
            colors: <Color>[
              Colors.green,
              Colors.blue,
            ],
          ),
        ),
        Expanded(
          child: ColorPages(
            colors: <Color>[
              Colors.red,
            ],
          ),
        ),
      ]),
    );
  }
}

class ColorPages extends StatefulWidget {
  final List<Color> colors;

  const ColorPages({Key key, this.colors}) : super(key: key);

  @override
  ColorPagesState createState() {
    return new ColorPagesState();
  }
}

class ColorPagesState extends State<ColorPages> {
  PageController _pageController;

  @override
  void initState() {
    super.initState();

    _pageController = new PageController(
      viewportFraction: 0.5,
    );
  }

  @override
  Widget build(BuildContext context) {
    return PageView.builder(
      controller: _pageController,
      itemBuilder: (context, index) {
        return GestureDetector(
          onTap: () {
            print(DateTime.now().toIso8601String() + " " + widget.colors[index].toString());
          },
          child: Container(
            color: widget.colors[index],
          ),
        );
      },
      itemCount: widget.colors.length,
    );
  }
}

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: gesturesflutter/packages/flutter/gestures repository.
    on Nov 3, 2018
  2. added this to the milestone on Nov 3, 2018
  3. zoechi commented on Nov 3, 2018

    @zoechi
    Contributor

    Please add the output of flutter doctor -v.

  4. rav3r commented on Nov 3, 2018

    @rav3r
    Author

    @zoechi

    [✓] Flutter (Channel beta, v0.9.4, on Linux, locale en_US.UTF-8)
        • Flutter version 0.9.4 at /home/rafal/Development/flutter
        • Framework revision f37c235c32 (6 weeks ago), 2018-09-25 17:45:40 -0400
        • Engine revision 74625aed32
        • Dart version 2.1.0-dev.5.0.flutter-a2eb050044
    
    [✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
        • Android SDK at /home/rafal/Development/android-sdk
        • Android NDK location not configured (optional; useful for native profiling support)
        • Platform android-27, build-tools 27.0.3
        • ANDROID_HOME = /home/rafal/Development/android-sdk
        • Java binary at: /home/rafal/Development/android-studio/jre/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
        • All Android licenses accepted.
    
    [✓] Android Studio (version 3.1)
        • Android Studio at /home/rafal/Development/android-studio
        • Flutter plugin version 28.0.1
        • Dart plugin version 173.4700
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    
    [!] IntelliJ IDEA Community Edition (version 2018.2)
        • IntelliJ at /home/rafal/Development/idea
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • For information about installing plugins, see
          https://flutter.io/intellij-setup/#installing-the-plugins
    
    [!] Connected devices
        ! No devices available
    
    ! Doctor found issues in 2 categories.
    
  5. parth181195 commented on Dec 9, 2018

    @parth181195

    I encountered a similar issue when using viewportFraction gesture detector is not working for the page that has index 1 and page 0 is active except this scenario everything is working fine.

  6. zoechi commented on Feb 25, 2019

    @zoechi
    Contributor

    Possible duplicate of #27744

  7. vitor-gyant commented on Jun 11, 2019

    @vitor-gyant

    @zoechi What is the status of this issue. I think I'm facing the same issue while trying to automatically snap clicks on pages that are not the current selected. Basically the GestureDetector that wraps the page items that have index > 0 do not trigger onTap. Any workaround ? thanks

  8. mehmetf commented on Nov 21, 2019

    @mehmetf
    Contributor

    This issue is blocking one of our internal clients from shipping as their account selector relies on PageView behavior that was fixed. Is there an ETA on the reland?

  9. vitor-gyant commented on Nov 22, 2019

    @vitor-gyant

    @mehmetf In which branch are you testing ?

  10. mehmetf commented on Nov 22, 2019

    @mehmetf
    Contributor

    Customer found a crude workaround.

    @vitor-gyant This is master. We use Flutter pretty close to ToT within Google.

  11. vitor-gyant commented on Nov 22, 2019

    @vitor-gyant

    @mehmetf This issue was fixed on master and I've verified it on my side since it was affecting our app too.

  12. mehmetf commented on Nov 22, 2019

    @mehmetf
    Contributor

    It was fixed in August, then the fix was reverted 10 days ago: #44778

    That's why the issue was reopened. They are trying to land it again.

  13. ankur141295 commented on Jan 22, 2020

    @ankur141295

    I am on SDK v1.12.13+hotfix.5 and still facing this issue. Is there any workaround?

  14. LongCatIsLooong commented on Jan 22, 2020

    @LongCatIsLooong
    Contributor

    @ankur141295 I'm not aware of an easy workaround that would work for everyone. You could switch to the beta branch or apply the patch locally. See https://github.com/flutter/flutter/wiki/Flutter-build-release-channels#will-a-particular-bug-fix-be-provided-in-a-hotfix-release.

  15. github-actions commented on Aug 14, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  16. locked as resolved and limited conversation to collaborators on Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

customer: googleVarious Google teamsf: gesturesflutter/packages/flutter/gestures repository.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions