Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2ad0ac0e
Unverified
Commit
2ad0ac0e
authored
Feb 23, 2022
by
xubaolin
Committed by
GitHub
Feb 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Draggable can be accepted when the data is null (#97355)
parent
9e7cc970
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
37 deletions
+130
-37
drag_and_drop.dart
dev/manual_tests/lib/drag_and_drop.dart
+3
-3
draggable.0.dart
examples/api/lib/widgets/drag_target/draggable.0.dart
+2
-2
drag_target.dart
packages/flutter/lib/src/widgets/drag_target.dart
+5
-5
draggable_test.dart
packages/flutter/test/widgets/draggable_test.dart
+120
-27
No files found.
dev/manual_tests/lib/drag_and_drop.dart
View file @
2ad0ac0e
...
@@ -16,9 +16,9 @@ class ExampleDragTarget extends StatefulWidget {
...
@@ -16,9 +16,9 @@ class ExampleDragTarget extends StatefulWidget {
class
ExampleDragTargetState
extends
State
<
ExampleDragTarget
>
{
class
ExampleDragTargetState
extends
State
<
ExampleDragTarget
>
{
Color
_color
=
Colors
.
grey
;
Color
_color
=
Colors
.
grey
;
void
_handleAccept
(
Color
data
)
{
void
_handleAccept
(
Color
?
data
)
{
setState
(()
{
setState
(()
{
_color
=
data
;
_color
=
data
!
;
});
});
}
}
...
@@ -215,7 +215,7 @@ class MovableBall extends StatelessWidget {
...
@@ -215,7 +215,7 @@ class MovableBall extends StatelessWidget {
);
);
}
else
{
}
else
{
return
DragTarget
<
bool
>(
return
DragTarget
<
bool
>(
onAccept:
(
bool
data
)
{
callback
(
position
);
},
onAccept:
(
bool
?
data
)
{
callback
(
position
);
},
builder:
(
BuildContext
context
,
List
<
bool
?>
accepted
,
List
<
dynamic
>
rejected
)
{
builder:
(
BuildContext
context
,
List
<
bool
?>
accepted
,
List
<
dynamic
>
rejected
)
{
return
dashedBall
;
return
dashedBall
;
},
},
...
...
examples/api/lib/widgets/drag_target/draggable.0.dart
View file @
2ad0ac0e
...
@@ -81,9 +81,9 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
...
@@ -81,9 +81,9 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
),
),
);
);
},
},
onAccept:
(
int
data
)
{
onAccept:
(
int
?
data
)
{
setState
(()
{
setState
(()
{
acceptedData
+=
data
;
acceptedData
+=
data
!
;
});
});
},
},
),
),
...
...
packages/flutter/lib/src/widgets/drag_target.dart
View file @
2ad0ac0e
...
@@ -20,7 +20,7 @@ typedef DragTargetWillAccept<T> = bool Function(T? data);
...
@@ -20,7 +20,7 @@ typedef DragTargetWillAccept<T> = bool Function(T? data);
/// Signature for causing a [DragTarget] to accept the given data.
/// Signature for causing a [DragTarget] to accept the given data.
///
///
/// Used by [DragTarget.onAccept].
/// Used by [DragTarget.onAccept].
typedef
DragTargetAccept
<
T
>
=
void
Function
(
T
data
);
typedef
DragTargetAccept
<
T
>
=
void
Function
(
T
?
data
);
/// Signature for determining information about the acceptance by a [DragTarget].
/// Signature for determining information about the acceptance by a [DragTarget].
///
///
...
@@ -638,7 +638,7 @@ class DragTargetDetails<T> {
...
@@ -638,7 +638,7 @@ class DragTargetDetails<T> {
DragTargetDetails
({
required
this
.
data
,
required
this
.
offset
})
:
assert
(
offset
!=
null
);
DragTargetDetails
({
required
this
.
data
,
required
this
.
offset
})
:
assert
(
offset
!=
null
);
/// The data that was dropped onto this [DragTarget].
/// The data that was dropped onto this [DragTarget].
final
T
data
;
final
T
?
data
;
/// The global position when the specific pointer event occurred on
/// The global position when the specific pointer event occurred on
/// the draggable.
/// the draggable.
...
@@ -767,14 +767,14 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
...
@@ -767,14 +767,14 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
setState
(()
{
setState
(()
{
_candidateAvatars
.
remove
(
avatar
);
_candidateAvatars
.
remove
(
avatar
);
});
});
widget
.
onAccept
?.
call
(
avatar
.
data
!
as
T
);
widget
.
onAccept
?.
call
(
avatar
.
data
as
T
?
);
widget
.
onAcceptWithDetails
?.
call
(
DragTargetDetails
<
T
>(
data:
avatar
.
data
!
as
T
,
offset:
avatar
.
_lastOffset
!));
widget
.
onAcceptWithDetails
?.
call
(
DragTargetDetails
<
T
>(
data:
avatar
.
data
as
T
?
,
offset:
avatar
.
_lastOffset
!));
}
}
void
didMove
(
_DragAvatar
<
Object
>
avatar
)
{
void
didMove
(
_DragAvatar
<
Object
>
avatar
)
{
if
(!
mounted
)
if
(!
mounted
)
return
;
return
;
widget
.
onMove
?.
call
(
DragTargetDetails
<
T
>(
data:
avatar
.
data
!
as
T
,
offset:
avatar
.
_lastOffset
!));
widget
.
onMove
?.
call
(
DragTargetDetails
<
T
>(
data:
avatar
.
data
as
T
?
,
offset:
avatar
.
_lastOffset
!));
}
}
@override
@override
...
...
packages/flutter/test/widgets/draggable_test.dart
View file @
2ad0ac0e
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment