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
5fe78541
Unverified
Commit
5fe78541
authored
Jun 03, 2022
by
Taha Tesser
Committed by
GitHub
Jun 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DataTable]: Add ability to only select row using checkbox (#105123)
parent
032dc542
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
1 deletion
+95
-1
data_table.dart
packages/flutter/lib/src/material/data_table.dart
+17
-1
data_table_test.dart
packages/flutter/test/material/data_table_test.dart
+78
-0
No files found.
packages/flutter/lib/src/material/data_table.dart
View file @
5fe78541
...
...
@@ -100,6 +100,7 @@ class DataRow {
this
.
selected
=
false
,
this
.
onSelectChanged
,
this
.
onLongPress
,
this
.
selectableOnGestures
=
true
,
this
.
color
,
required
this
.
cells
,
})
:
assert
(
cells
!=
null
);
...
...
@@ -113,6 +114,7 @@ class DataRow {
this
.
selected
=
false
,
this
.
onSelectChanged
,
this
.
onLongPress
,
this
.
selectableOnGestures
=
true
,
this
.
color
,
required
this
.
cells
,
})
:
assert
(
cells
!=
null
),
...
...
@@ -163,6 +165,18 @@ class DataRow {
/// Otherwise, the checkbox, if present, will not be checked.
final
bool
selected
;
/// Whether the row can be selected by using gestures such as
/// tap or long press.
///
/// If the value is set to false and [onSelectChanged] is non-null,
/// the row can be only selected by toggling the checkbox.
///
/// If the value is set to false and [onLongPress] is non-null,
/// [onLongPress] callback won't be called.
///
/// This value is true by default.
final
bool
selectableOnGestures
;
/// The data for this row.
///
/// There must be exactly as many cells as there are columns in the
...
...
@@ -807,6 +821,7 @@ class DataTable extends StatelessWidget {
required
GestureTapCancelCallback
?
onTapCancel
,
required
MaterialStateProperty
<
Color
?>?
overlayColor
,
required
GestureLongPressCallback
?
onRowLongPress
,
required
bool
selectableOnGestures
,
})
{
final
ThemeData
themeData
=
Theme
.
of
(
context
);
final
DataTableThemeData
dataTableTheme
=
DataTableTheme
.
of
(
context
);
...
...
@@ -852,7 +867,7 @@ class DataTable extends StatelessWidget {
overlayColor:
overlayColor
,
child:
label
,
);
}
else
if
(
onSelectChanged
!=
null
||
onRowLongPress
!=
null
)
{
}
else
if
(
selectableOnGestures
&&
(
onSelectChanged
!=
null
||
onRowLongPress
!=
null
)
)
{
label
=
TableRowInkWell
(
onTap:
onSelectChanged
,
onLongPress:
onRowLongPress
,
...
...
@@ -1031,6 +1046,7 @@ class DataTable extends StatelessWidget {
onSelectChanged:
row
.
onSelectChanged
==
null
?
null
:
()
=>
row
.
onSelectChanged
?.
call
(!
row
.
selected
),
overlayColor:
row
.
color
??
effectiveDataRowColor
,
onRowLongPress:
row
.
onLongPress
,
selectableOnGestures:
row
.
selectableOnGestures
,
);
rowIndex
+=
1
;
}
...
...
packages/flutter/test/material/data_table_test.dart
View file @
5fe78541
...
...
@@ -293,6 +293,84 @@ void main() {
log
.
clear
();
});
testWidgets
(
'selectableOnGestures disables gestures on row'
,
(
WidgetTester
tester
)
async
{
final
List
<
String
>
log
=
<
String
>[];
Widget
buildTable
({
int
?
sortColumnIndex
,
bool
sortAscending
=
true
})
{
return
DataTable
(
sortColumnIndex:
sortColumnIndex
,
sortAscending:
sortAscending
,
onSelectAll:
(
bool
?
value
)
{
log
.
add
(
'select-all:
$value
'
);
},
columns:
<
DataColumn
>[
const
DataColumn
(
label:
Text
(
'Name'
),
tooltip:
'Name'
,
),
DataColumn
(
label:
const
Text
(
'Calories'
),
tooltip:
'Calories'
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
{
log
.
add
(
'column-sort:
$columnIndex
$ascending
'
);
},
),
],
rows:
kDesserts
.
map
<
DataRow
>((
Dessert
dessert
)
{
return
DataRow
(
key:
ValueKey
<
String
>(
dessert
.
name
),
selectableOnGestures:
false
,
onSelectChanged:
(
bool
?
selected
)
{
log
.
add
(
'row-selected:
${dessert.name}
'
);
},
onLongPress:
()
{
log
.
add
(
'onLongPress:
${dessert.name}
'
);
},
cells:
<
DataCell
>[
DataCell
(
Text
(
dessert
.
name
),
),
DataCell
(
Text
(
'
${dessert.calories}
'
),
showEditIcon:
true
,
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}
'
);
},
),
],
);
}).
toList
(),
);
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
buildTable
()),
));
await
tester
.
tap
(
find
.
text
(
'KitKat'
));
expect
(
log
.
length
,
0
);
await
tester
.
longPress
(
find
.
text
(
'KitKat'
));
expect
(
log
.
length
,
0
);
await
tester
.
tap
(
find
.
byType
(
Checkbox
).
last
);
expect
(
log
,
<
String
>[
'row-selected: KitKat'
]);
log
.
clear
();
});
testWidgets
(
'DataTable overflow test - header'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
...
...
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