Skip to content

TabBar does not allow detection of taps #24224

Description

@JaspervanRiet

Problem

We have come up against a wall in our project because of this a couple times now. The latest example is as follows:

We have a TabBar with two Tabs, both of which contain lists. If we are in Tab X, and the user taps on the header for Tab X, we want to scroll the list up to the top. If the user taps Tab Y, we of course want to animate there. This currently seems to be impossible. We can wrap a GestureDetector around a Tab child of TabBar and sort of intercept taps, but this only works for the actual icon and text of the Tab, not the padding around it. Moreover, it disables the normal reaction to taps on the icon and text (tabs no longer switch when tapping there).

Another example would be bookkeeping of the current tab index. The TabController does allow for access to the index, and we can be notified by subscribing to the TabController, but it cannot be trusted because of the following behaviour:

When tapping on a tab:

  1. Notified
  2. Widget is built
  3. Notified

When swiping to a tab:

  1. Widget is built
  2. Notified

This means that it is impossible to react to swipes and we always need to be aware of the fact that we might currently be in a swipe, but the system is simply not telling us. As a result, we cannot keep track of
the current index of tabs, since it can be corrupted by a simple swipe (and any workarounds are unnecessarily complicated).

Finally, while this is not something we need, it is also currrently impossible to disable tapping on the TabBar, see this SO question.

Fix

See PR #23919

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    on Nov 12, 2018
  2. added this to the milestone on Nov 12, 2018
  3. Hixie commented on Nov 14, 2018

    @Hixie
    Contributor
  4. Hixie commented on Nov 20, 2018

    @Hixie
    Contributor

    Disabling tabs entirely is possible with IgnorePointer.

    So is the request here merely to be told when the user taps on a Tab that is already showing?

  5. JaspervanRiet commented on Nov 20, 2018

    @JaspervanRiet
    ContributorAuthor

    Wasn't aware of that. Our specific request is to be told when a user taps on a tab, and be given the index of the tab, so that we can take action based on this tap.

  6. Hixie commented on Nov 20, 2018

    @Hixie
    Contributor

    Would it be sufficient to take the approach in #23919 but always call _handleTap regardless, instead of having the onTap handler override it?

  7. JaspervanRiet commented on Nov 20, 2018

    @JaspervanRiet
    ContributorAuthor

    Yes, that would be the suggestion I provided in #23919 which would work for us just fine (and is what we've actually implemented locally to give us this functionality). Could basically take my pull request and make that slight change to it and it would work.

  8. JaspervanRiet commented on Nov 28, 2018

    @JaspervanRiet
    ContributorAuthor

    @Hixie #23919 now incorporates your suggestion.

  9. JaspervanRiet commented on Dec 12, 2018

    @JaspervanRiet
    ContributorAuthor

    This issue is actually fixed once #23919 is merged. #24892 actually fixes #24424

  10. HansMuller commented on Dec 12, 2018

    @HansMuller
    Contributor

    Sorry, bad bookeeping. I just merged #23919 and will try and land it today.

  11. 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.

  12. 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

Assignees

No one assigned

    Labels

    frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packageswaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions