Skip to content

Remove Primary Scroll Controller for Flutter Desktop apps #100264

Description

@domesticmouse

Common desktop error: The provided ScrollController is currently attached to more than one ScrollPosition.

From medium article: https://andrewzuo.com/flutter-for-desktop-apps-isnt-ready-yet-663664262dde

For context, desktop apps frequently have multiple vertical scroll areas, e.g. desktop_photo_search has a sidebar and mainn content area, both of which scroll vertically.

This combination results in a runtime error from a cranky primary scroll controller, as mentioned above. Work around is manually instantiate a scroll controller, e.g. https://github.com/flutter/samples/blob/master/desktop_photo_search/material/lib/src/widgets/unsplash_search_content.dart#L23

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: proposalA detailed proposal for a change to Flutter
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    p: material_uimaterial_ui package in flutter/packages
    and removed
    in triagePresently being triaged by the triage team
    on Mar 17, 2022
  2. Piinks commented on Mar 17, 2022

    @Piinks
    Contributor

    So I think the primary scroll controller is only used in the framework to automatically support the iOS scroll to top function. If this is true, we can likely disable the PSC automatically attaching to every vertical scroll position on desktop...

    I need to investigate if the PSC is relied upon for anything else that would make such a change a breaking one.

  3. added
    P2Important issues not at the top of the work list
    on Mar 17, 2022
  4. Piinks commented on Mar 29, 2022

    @Piinks
    Contributor

    Unfortunately I do not think this will be ass straightforward as I had hoped. Couple of findings:

    1. The PrimaryScrollController is also used in the NestedScrollView in order to have the inner scroll view inherit the scroll controller that it manipulates to keep the 2 positions in sync.
    • So we would have to find a way around this or it would break the NestedScrollView for desktop applications.
    1. Default keyboard scroll actions on desktop actually rely on the PrimaryScrollController to work. A PSC is created for each route, and when the user taps the arrow keys, if the current focus is not enclosed by a scrollable, it looks up the PSC as a fallback to automatically have keyboard scrolling shortcuts work.
    • In this case, I think the same more than one position attached... issue actually applies to scroll actions too, if not I do not think the user would want multiple scroll views to move in response to a key stroke. If we disable the automatic attachment of PSC completely, the user would have to specify which scrollview they want to be the default for scroll actions by setting ScrollView.primary to true. I think this would be an ok trade-off but it is still one to consider carefully.

    ⭐ ➡️ I think for now, the best workaround is to set primary: false on ScrollViews that should not connect to the PSC. I think it is better than setting an individual scroll controller for each.

    If anyone has thoughts on this, please do share. I am still investigating a few more options here.

  5. github-actions commented on Jun 23, 2022

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

  6. locked as resolved and limited conversation to collaborators on Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopc: proposalA detailed proposal for a change to Flutterf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions