Skip to content

Draggable should allow to specify PointerDeviceKinds capable of triggering a drag #91288

@jagmit

Description

@jagmit

Use case

Let's say you have a list of items and you want to enable a faster drag and drop interaction on each item. This is especially something that users on a desktop platform would expect.

Code sample
import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      body: ListView(
        children: [
          for (int i = 0; i < 20; i++)
            Draggable<int>(
              data: i,
              feedback: Card(
                child: Text("Contact $i"),
              ),
              dragAnchor: DragAnchor.pointer,
              child: ListTile(
                leading: const Icon(Icons.contact_mail_rounded),
                title: Text("Contact $i"),
              ),
            ),
        ],
      ),
      floatingActionButton: DragTarget<int>(
        onWillAccept: (data) => true,
        builder: (context, candidateData, __) => (candidateData.isEmpty)
            ? FloatingActionButton(
                onPressed: () {},
                child: Icon(Icons.delete),
              )
            : FloatingActionButton.large(
                onPressed: () {},
                child: Icon(Icons.check),
              ),
      ),
    ),
  );
}
}

On mouse-based devices this works fine, but on touch-based ones the regular list scroll competes with the drag gesture on each list item.

Proposal

Draggable should allow to specify which PointerDeviceKinds should be allowed to trigger a drag gesture.

A possible API example
  const Draggable<T extends Object>(
{Key? key,
required Widget child,
required Widget feedback,
T? data,
...
List<PointerDeviceKind> pointerKinds = PointerDeviceKind.values,
...
)

This should subsequently also be done for LongPressDraggable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: desktopRunning on desktopa: qualityA truly polished experiencec: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions