Skip to content

expose the moveController of the Dismissible widget #74582

Closed

Description

@dvdlg

My proposal is to expose an interface for the Dismissible widget (in the flutter/material.dart package) to show the value of the current offset in which the item has been dragged.

In my use case I wanted to implement an animation of an object fading in while the dismissible is beeing dismissed, in such a way that the offset of the dismissed item equals the opacity at each moment. I was able to do so only by changing _DismissibleState, _moveController and _dragExtent from private to public. I used flutter stable channel 1.22.5.

My code looks like this:

GlobalKey<DismissibleState> currentKey = GlobalKey<DismissibleState>();

...

@override
Widget build(BuildContext context) {
  ...
  Listener(
    onPointerDown: (PointerDownEvent event) {
      currentKey.currentState.moveController.removeListener(dragListener);
      currentKey.currentState.moveController.addListener(dragListener);
    },
    child: Dismissible(
      key: currentKey,
      onDismissed: (direction) {
        currentKey.currentState.moveController.removeListener(dragListener);
        // do some more stuff ...
      },
      child: ...,
      ...
    ),
  ...
}

...

@override
void dispose() {
  currentKey.currentState.moveController.removeListener(dragListener);
  super.dispose();
}

where dragListener uses moveController.value and dragExtent.sign to set the state of the faded object.

I tried to do it without changing the flutter base code, by listening to onPointerDown, onPointerUp and onPointerMove events, but then I had to compute myself the offset and it was very buggy because there are many cases were the user can do funny stuff.

I couldn't find any other solution on the internet. I would appriciate if this could become available in future release.

Kind regards

Activity

  1. pedromassangocode commented on Jan 25, 2021

    @pedromassangocode

    Related to #21230.

  2. github-actions commented on Feb 19, 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.

  3. locked as resolved and limited conversation to collaborators on Feb 19, 2022
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

    c: proposalA detailed proposal for a change to Flutterframeworkflutter/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