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
a178bba5
Unverified
Commit
a178bba5
authored
Feb 11, 2021
by
Rashid-Khabeer
Committed by
GitHub
Feb 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add onLongPress property to DataCell: #72609 (#75393)
parent
705cebb2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
8 deletions
+106
-8
data_table.dart
packages/flutter/lib/src/material/data_table.dart
+61
-7
data_table_test.dart
packages/flutter/test/material/data_table_test.dart
+45
-1
No files found.
packages/flutter/lib/src/material/data_table.dart
View file @
a178bba5
...
...
@@ -206,6 +206,10 @@ class DataCell {
this
.
placeholder
=
false
,
this
.
showEditIcon
=
false
,
this
.
onTap
,
this
.
onLongPress
,
this
.
onTapDown
,
this
.
onDoubleTap
,
this
.
onTapCancel
,
})
:
assert
(
child
!=
null
);
/// A cell that has no content and has zero width and height.
...
...
@@ -241,14 +245,48 @@ class DataCell {
/// Called if the cell is tapped.
///
/// If non-null, tapping the cell will call this callback. If
/// null, tapping the cell will attempt to select the row (if
/// null (including [onDoubleTap], [onLongPress], [onTapCancel] and [onTapDown]),
/// tapping the cell will attempt to select the row (if
/// [DataRow.onSelectChanged] is provided).
final
GestureTapCallback
?
onTap
;
/// Called when the cell is double tapped.
///
/// If non-null, tapping the cell will call this callback. If
/// null (including [onTap], [onLongPress], [onTapCancel] and [onTapDown]),
/// tapping the cell will attempt to select the row (if
/// [DataRow.onSelectChanged] is provided).
final
GestureTapCallback
?
onDoubleTap
;
/// Called if the cell is long-pressed.
///
/// If non-null, tapping the cell will invoke this callback. If
/// null (including [onDoubleTap], [onTap], [onTapCancel] and [onTapDown]),
/// tapping the cell will attempt to select the row (if
/// [DataRow.onSelectChanged] is provided).
final
GestureLongPressCallback
?
onLongPress
;
/// Called if the cell is tapped down.
///
/// To define a tap behavior for the entire row, see
/// [DataRow.onSelectChanged].
final
VoidCallback
?
onTap
;
/// If non-null, tapping the cell will call this callback. If
/// null (including [onTap] [onDoubleTap], [onLongPress] and [onTapCancel]),
/// tapping the cell will attempt to select the row (if
/// [DataRow.onSelectChanged] is provided).
final
GestureTapDownCallback
?
onTapDown
;
bool
get
_debugInteractive
=>
onTap
!=
null
;
/// Called if the user cancels a tap was started on cell.
///
/// If non-null, cancelling the tap gesture will invoke this callback.
/// If null (including [onTap], [onDoubleTap] and [onLongPress]),
/// tapping the cell will attempt to select the
/// row (if [DataRow.onSelectChanged] is provided).
final
GestureTapCancelCallback
?
onTapCancel
;
bool
get
_debugInteractive
=>
onTap
!=
null
||
onDoubleTap
!=
null
||
onLongPress
!=
null
||
onTapDown
!=
null
||
onTapCancel
!=
null
;
}
/// A material design data table.
...
...
@@ -809,8 +847,12 @@ class DataTable extends StatelessWidget {
required
bool
numeric
,
required
bool
placeholder
,
required
bool
showEditIcon
,
required
Void
Callback
?
onTap
,
required
GestureTap
Callback
?
onTap
,
required
VoidCallback
?
onSelectChanged
,
required
GestureTapCallback
?
onDoubleTap
,
required
GestureLongPressCallback
?
onLongPress
,
required
GestureTapDownCallback
?
onTapDown
,
required
GestureTapCancelCallback
?
onTapCancel
,
required
MaterialStateProperty
<
Color
?>?
overlayColor
,
})
{
final
ThemeData
themeData
=
Theme
.
of
(
context
);
...
...
@@ -840,9 +882,17 @@ class DataTable extends StatelessWidget {
child:
DropdownButtonHideUnderline
(
child:
label
),
),
);
if
(
onTap
!=
null
)
{
if
(
onTap
!=
null
||
onDoubleTap
!=
null
||
onLongPress
!=
null
||
onTapDown
!=
null
||
onTapCancel
!=
null
)
{
label
=
InkWell
(
onTap:
onTap
,
onDoubleTap:
onDoubleTap
,
onLongPress:
onLongPress
,
onTapCancel:
onTapCancel
,
onTapDown:
onTapDown
,
child:
label
,
overlayColor:
overlayColor
,
);
...
...
@@ -1000,6 +1050,10 @@ class DataTable extends StatelessWidget {
placeholder:
cell
.
placeholder
,
showEditIcon:
cell
.
showEditIcon
,
onTap:
cell
.
onTap
,
onDoubleTap:
cell
.
onDoubleTap
,
onLongPress:
cell
.
onLongPress
,
onTapCancel:
cell
.
onTapCancel
,
onTapDown:
cell
.
onTapDown
,
onSelectChanged:
()
=>
row
.
onSelectChanged
!=
null
?
row
.
onSelectChanged
!(!
row
.
selected
)
:
null
,
overlayColor:
row
.
color
??
effectiveDataRowColor
,
);
...
...
packages/flutter/test/material/data_table_test.dart
View file @
a178bba5
...
...
@@ -54,6 +54,18 @@ void main() {
onTap:
()
{
log
.
add
(
'cell-tap:
${dessert.calories}
'
);
},
onDoubleTap:
()
{
log
.
add
(
'cell-doubleTap:
${dessert.calories}
'
);
},
onLongPress:
()
{
log
.
add
(
'cell-longPress:
${dessert.calories}
'
);
},
onTapCancel:
()
{
log
.
add
(
'cell-tapCancel:
${dessert.calories}
'
);
},
onTapDown:
(
TapDownDetails
details
)
{
log
.
add
(
'cell-tapDown:
${dessert.calories}
'
);
},
),
],
);
...
...
@@ -95,8 +107,40 @@ void main() {
await
tester
.
pumpAndSettle
(
const
Duration
(
milliseconds:
200
));
await
tester
.
tap
(
find
.
text
(
'375'
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
await
tester
.
tap
(
find
.
text
(
'375'
));
expect
(
log
,
<
String
>[
'cell-doubleTap: 375'
]);
log
.
clear
();
await
tester
.
longPress
(
find
.
text
(
'375'
));
// The tap down is triggered on gesture down.
// Then, the cancel is triggered when the gesture arena
// recognizes that the long press overrides the tap event
// so it triggers a tap cancel, followed by the long press.
expect
(
log
,<
String
>[
'cell-tapDown: 375'
,
'cell-tapCancel: 375'
,
'cell-longPress: 375'
]);
log
.
clear
();
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getRect
(
find
.
text
(
'375'
)).
center
,
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
// onTapDown callback is registered.
expect
(
log
,
equals
(<
String
>[
'cell-tapDown: 375'
]));
await
gesture
.
up
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// onTap callback is registered after the gesture is removed.
expect
(
log
,
equals
(<
String
>[
'cell-tapDown: 375'
,
'cell-tap: 375'
]));
log
.
clear
();
// dragging off the bounds of the cell calls the cancel callback
gesture
=
await
tester
.
startGesture
(
tester
.
getRect
(
find
.
text
(
'375'
)).
center
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
100
));
await
gesture
.
moveBy
(
const
Offset
(
0.0
,
200.0
));
await
gesture
.
cancel
();
expect
(
log
,
equals
(<
String
>[
'cell-tapDown: 375'
,
'cell-tapCancel: 375'
]));
expect
(
log
,
<
String
>[
'cell-tap: 375'
]);
log
.
clear
();
await
tester
.
tap
(
find
.
byType
(
Checkbox
).
last
);
...
...
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