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,
),
),
);
},
),
),
],
),
),
],
),
);
}
}
Steps to reproduce
DragTarget,rejecting allDraggable, above a second one.Draggable. The draggable is correctly handled by the firstDragTarget.Draggableis not received by the secondDragTargetSee 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
DragTargetrejecting all draggable to track the movements of draggables inside a regionActual results
The
DragTargetbehind does not receiveDraggable.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.flutter/packages/flutter/lib/src/widgets/drag_target.dart
Lines 863 to 877 in 92c7ba8
Code sample
Code sample
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output