Skip to content

expose the moveController of the Dismissible widget #74582

@dvdlg

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material 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