Skip to content

Issue with stacked DragTargets #143156

Description

@lecuivre-alban

Steps to reproduce

  1. Have a first DragTarget,rejecting all Draggable, above a second one.
  2. Start dragging a Draggable. The draggable is correctly handled by the first DragTarget.
  3. The Draggable is not received by the second DragTarget

See the code sample to reproduce.

Expected results

The draggable should be received by the DragTarget visually behind, because the above DragTarget rejected the draggable

Note: In my app, I added this DragTarget rejecting all draggable to track the movements of draggables inside a region

Actual results

The DragTarget behind does not receive Draggable.

I don't understand what's trying to acheive the following bit of code but when I replace >= with ==, I have the expected result. But I guess it create other issues.

final List<_DragTargetState<Object>> targets = _getDragTargets(result.path).toList();
bool listsMatch = false;
if (targets.length >= _enteredTargets.length && _enteredTargets.isNotEmpty) {
listsMatch = true;
final Iterator<_DragTargetState<Object>> iterator = targets.iterator;
for (int i = 0; i < _enteredTargets.length; i += 1) {
iterator.moveNext();
if (iterator.current != _enteredTargets[i]) {
listsMatch = false;
break;
}
}
}

Code sample

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(20.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Builder(
                  builder: (context) {
                    final child = Container(
                      width: 200,
                      height: 125,
                      color: Colors.green,
                    );

                    return Draggable<String>(
                      data: "data",
                      feedback: child,
                      childWhenDragging: Opacity(opacity: 0.5, child: child),
                      child: child,
                    );
                  },
                ),
              ],
            ),
          ),
          Expanded(
            child: Stack(
              children: [
                Center(
                  child: DragTarget(
                    onWillAccept: (_) => true,
                    builder: (context, candidates, _) => Container(
                      color: Colors.yellow,
                      width: 250,
                      height: 250,
                      alignment: Alignment.center,
                      child: candidates.isNotEmpty
                          ? const Icon(Icons.check, size: 48)
                          : null,
                    ),
                  ),
                ),
                Positioned.fill(
                  child: DragTarget(
                    onWillAccept: (_) => false,
                    builder: (context, candidates, rejected) {
                      return IgnorePointer(
                        child: Container(
                          alignment: Alignment.topLeft,
                          padding: const EdgeInsets.all(10),
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: rejected.isEmpty
                                  ? Colors.blue
                                  : Colors.purple,
                              width: 5,
                            ),
                          ),
                          child: Text(
                            "Entered: ${rejected.length}",
                            style: Theme.of(context).textTheme.headlineSmall,
                          ),
                        ),
                      );
                    },
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [version 10.0.22621.3085], locale fr-FR)
    • Flutter version 3.10.0 on channel stable at C:\...
    • Upstream repository http://...
    • FLUTTER_GIT_URL = http://...
    • Framework revision 84a1e904f4 (9 months ago), 2023-05-09 07:41:44 -0700
    • Engine revision d44b5a94c9
    • Dart version 3.0.0
    • DevTools version 2.23.1
    • Pub download mirror http://...

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\...
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\...
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[√] Chrome - develop for the web
    • Chrome at C:\...

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.0)
    • Visual Studio at C:\...
    • Visual Studio Community 2022 version 17.0.31903.59
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2022.2)
    • Android Studio at C:\...
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] VS Code (version 1.85.0)
    • VS Code at C:\...
    • Flutter extension version 3.80.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [version 10.0.22621.3085]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 121.0.6167.85
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 119.0.2151.58

[!] Network resources
    X An HTTP error occurred while checking "https://maven.google.com/": Proxy failed to establish tunnel (403 Forbidden)
    X An HTTP error occurred while checking "https://cocoapods.org/": Proxy failed to establish tunnel (403 Forbidden)
    X An HTTP error occurred while checking "https://github.com/": Proxy failed to establish tunnel (403 Forbidden)

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectfound in release: 3.16Found to occur in 3.16found in release: 3.20Found to occur in 3.20frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-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