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
bf296f71
Commit
bf296f71
authored
Jan 23, 2017
by
Adam Barth
Committed by
GitHub
Jan 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test DataTable (#7591)
This patch adds a basic test for the DataTable widget.
parent
94cac1a6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
233 additions
and
97 deletions
+233
-97
data_table_demo.dart
examples/flutter_gallery/lib/demo/data_table_demo.dart
+91
-91
data_table.dart
packages/flutter/lib/src/material/data_table.dart
+5
-4
paginated_data_table.dart
packages/flutter/lib/src/material/paginated_data_table.dart
+12
-2
data_table_test.dart
packages/flutter/test/material/data_table_test.dart
+125
-0
No files found.
examples/flutter_gallery/lib/demo/data_table_demo.dart
View file @
bf296f71
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/rendering.dart'
;
class
Desert
{
class
Des
s
ert
{
Desert
(
this
.
name
,
this
.
calories
,
this
.
fat
,
this
.
carbs
,
this
.
protein
,
this
.
sodium
,
this
.
calcium
,
this
.
iron
);
Des
s
ert
(
this
.
name
,
this
.
calories
,
this
.
fat
,
this
.
carbs
,
this
.
protein
,
this
.
sodium
,
this
.
calcium
,
this
.
iron
);
final
String
name
;
final
String
name
;
final
int
calories
;
final
int
calories
;
final
double
fat
;
final
double
fat
;
...
@@ -19,68 +19,68 @@ class Desert {
...
@@ -19,68 +19,68 @@ class Desert {
bool
selected
=
false
;
bool
selected
=
false
;
}
}
class
DesertDataSource
extends
DataTableSource
{
class
Des
s
ertDataSource
extends
DataTableSource
{
final
List
<
Des
ert
>
_deserts
=
<
De
sert
>[
final
List
<
Des
sert
>
_desserts
=
<
Des
sert
>[
new
Desert
(
'Frozen yogurt'
,
159
,
6.0
,
24
,
4.0
,
87
,
14
,
1
),
new
Des
s
ert
(
'Frozen yogurt'
,
159
,
6.0
,
24
,
4.0
,
87
,
14
,
1
),
new
Desert
(
'Ice cream sandwich'
,
237
,
9.0
,
37
,
4.3
,
129
,
8
,
1
),
new
Des
s
ert
(
'Ice cream sandwich'
,
237
,
9.0
,
37
,
4.3
,
129
,
8
,
1
),
new
Desert
(
'Eclair'
,
262
,
16.0
,
24
,
6.0
,
337
,
6
,
7
),
new
Des
s
ert
(
'Eclair'
,
262
,
16.0
,
24
,
6.0
,
337
,
6
,
7
),
new
Desert
(
'Cupcake'
,
305
,
3.7
,
67
,
4.3
,
413
,
3
,
8
),
new
Des
s
ert
(
'Cupcake'
,
305
,
3.7
,
67
,
4.3
,
413
,
3
,
8
),
new
Desert
(
'Gingerbread'
,
356
,
16.0
,
49
,
3.9
,
327
,
7
,
16
),
new
Des
s
ert
(
'Gingerbread'
,
356
,
16.0
,
49
,
3.9
,
327
,
7
,
16
),
new
Desert
(
'Jelly bean'
,
375
,
0.0
,
94
,
0.0
,
50
,
0
,
0
),
new
Des
s
ert
(
'Jelly bean'
,
375
,
0.0
,
94
,
0.0
,
50
,
0
,
0
),
new
Desert
(
'Lollipop'
,
392
,
0.2
,
98
,
0.0
,
38
,
0
,
2
),
new
Des
s
ert
(
'Lollipop'
,
392
,
0.2
,
98
,
0.0
,
38
,
0
,
2
),
new
Desert
(
'Honeycomb'
,
408
,
3.2
,
87
,
6.5
,
562
,
0
,
45
),
new
Des
s
ert
(
'Honeycomb'
,
408
,
3.2
,
87
,
6.5
,
562
,
0
,
45
),
new
Desert
(
'Donut'
,
452
,
25.0
,
51
,
4.9
,
326
,
2
,
22
),
new
Des
s
ert
(
'Donut'
,
452
,
25.0
,
51
,
4.9
,
326
,
2
,
22
),
new
Desert
(
'KitKat'
,
518
,
26.0
,
65
,
7.0
,
54
,
12
,
6
),
new
Des
s
ert
(
'KitKat'
,
518
,
26.0
,
65
,
7.0
,
54
,
12
,
6
),
new
Desert
(
'Frozen yogurt with sugar'
,
168
,
6.0
,
26
,
4.0
,
87
,
14
,
1
),
new
Des
s
ert
(
'Frozen yogurt with sugar'
,
168
,
6.0
,
26
,
4.0
,
87
,
14
,
1
),
new
Desert
(
'Ice cream sandwich with sugar'
,
246
,
9.0
,
39
,
4.3
,
129
,
8
,
1
),
new
Des
s
ert
(
'Ice cream sandwich with sugar'
,
246
,
9.0
,
39
,
4.3
,
129
,
8
,
1
),
new
Desert
(
'Eclair with sugar'
,
271
,
16.0
,
26
,
6.0
,
337
,
6
,
7
),
new
Des
s
ert
(
'Eclair with sugar'
,
271
,
16.0
,
26
,
6.0
,
337
,
6
,
7
),
new
Desert
(
'Cupcake with sugar'
,
314
,
3.7
,
69
,
4.3
,
413
,
3
,
8
),
new
Des
s
ert
(
'Cupcake with sugar'
,
314
,
3.7
,
69
,
4.3
,
413
,
3
,
8
),
new
Desert
(
'Gingerbread with sugar'
,
345
,
16.0
,
51
,
3.9
,
327
,
7
,
16
),
new
Des
s
ert
(
'Gingerbread with sugar'
,
345
,
16.0
,
51
,
3.9
,
327
,
7
,
16
),
new
Desert
(
'Jelly bean with sugar'
,
364
,
0.0
,
96
,
0.0
,
50
,
0
,
0
),
new
Des
s
ert
(
'Jelly bean with sugar'
,
364
,
0.0
,
96
,
0.0
,
50
,
0
,
0
),
new
Desert
(
'Lollipop with sugar'
,
401
,
0.2
,
100
,
0.0
,
38
,
0
,
2
),
new
Des
s
ert
(
'Lollipop with sugar'
,
401
,
0.2
,
100
,
0.0
,
38
,
0
,
2
),
new
Desert
(
'Honeycomb with sugar'
,
417
,
3.2
,
89
,
6.5
,
562
,
0
,
45
),
new
Des
s
ert
(
'Honeycomb with sugar'
,
417
,
3.2
,
89
,
6.5
,
562
,
0
,
45
),
new
Desert
(
'Donut with sugar'
,
461
,
25.0
,
53
,
4.9
,
326
,
2
,
22
),
new
Des
s
ert
(
'Donut with sugar'
,
461
,
25.0
,
53
,
4.9
,
326
,
2
,
22
),
new
Desert
(
'KitKat with sugar'
,
527
,
26.0
,
67
,
7.0
,
54
,
12
,
6
),
new
Des
s
ert
(
'KitKat with sugar'
,
527
,
26.0
,
67
,
7.0
,
54
,
12
,
6
),
new
Desert
(
'Frozen yogurt with honey'
,
223
,
6.0
,
36
,
4.0
,
87
,
14
,
1
),
new
Des
s
ert
(
'Frozen yogurt with honey'
,
223
,
6.0
,
36
,
4.0
,
87
,
14
,
1
),
new
Desert
(
'Ice cream sandwich with honey'
,
301
,
9.0
,
49
,
4.3
,
129
,
8
,
1
),
new
Des
s
ert
(
'Ice cream sandwich with honey'
,
301
,
9.0
,
49
,
4.3
,
129
,
8
,
1
),
new
Desert
(
'Eclair with honey'
,
326
,
16.0
,
36
,
6.0
,
337
,
6
,
7
),
new
Des
s
ert
(
'Eclair with honey'
,
326
,
16.0
,
36
,
6.0
,
337
,
6
,
7
),
new
Desert
(
'Cupcake with honey'
,
369
,
3.7
,
79
,
4.3
,
413
,
3
,
8
),
new
Des
s
ert
(
'Cupcake with honey'
,
369
,
3.7
,
79
,
4.3
,
413
,
3
,
8
),
new
Desert
(
'Gingerbread with honey'
,
420
,
16.0
,
61
,
3.9
,
327
,
7
,
16
),
new
Des
s
ert
(
'Gingerbread with honey'
,
420
,
16.0
,
61
,
3.9
,
327
,
7
,
16
),
new
Desert
(
'Jelly bean with honey'
,
439
,
0.0
,
106
,
0.0
,
50
,
0
,
0
),
new
Des
s
ert
(
'Jelly bean with honey'
,
439
,
0.0
,
106
,
0.0
,
50
,
0
,
0
),
new
Desert
(
'Lollipop with honey'
,
456
,
0.2
,
110
,
0.0
,
38
,
0
,
2
),
new
Des
s
ert
(
'Lollipop with honey'
,
456
,
0.2
,
110
,
0.0
,
38
,
0
,
2
),
new
Desert
(
'Honeycomb with honey'
,
472
,
3.2
,
99
,
6.5
,
562
,
0
,
45
),
new
Des
s
ert
(
'Honeycomb with honey'
,
472
,
3.2
,
99
,
6.5
,
562
,
0
,
45
),
new
Desert
(
'Donut with honey'
,
516
,
25.0
,
63
,
4.9
,
326
,
2
,
22
),
new
Des
s
ert
(
'Donut with honey'
,
516
,
25.0
,
63
,
4.9
,
326
,
2
,
22
),
new
Desert
(
'KitKat with honey'
,
582
,
26.0
,
77
,
7.0
,
54
,
12
,
6
),
new
Des
s
ert
(
'KitKat with honey'
,
582
,
26.0
,
77
,
7.0
,
54
,
12
,
6
),
new
Desert
(
'Frozen yogurt with milk'
,
262
,
8.4
,
36
,
12.0
,
194
,
44
,
1
),
new
Des
s
ert
(
'Frozen yogurt with milk'
,
262
,
8.4
,
36
,
12.0
,
194
,
44
,
1
),
new
Desert
(
'Ice cream sandwich with milk'
,
339
,
11.4
,
49
,
12.3
,
236
,
38
,
1
),
new
Des
s
ert
(
'Ice cream sandwich with milk'
,
339
,
11.4
,
49
,
12.3
,
236
,
38
,
1
),
new
Desert
(
'Eclair with milk'
,
365
,
18.4
,
36
,
14.0
,
444
,
36
,
7
),
new
Des
s
ert
(
'Eclair with milk'
,
365
,
18.4
,
36
,
14.0
,
444
,
36
,
7
),
new
Desert
(
'Cupcake with milk'
,
408
,
6.1
,
79
,
12.3
,
520
,
33
,
8
),
new
Des
s
ert
(
'Cupcake with milk'
,
408
,
6.1
,
79
,
12.3
,
520
,
33
,
8
),
new
Desert
(
'Gingerbread with milk'
,
459
,
18.4
,
61
,
11.9
,
434
,
37
,
16
),
new
Des
s
ert
(
'Gingerbread with milk'
,
459
,
18.4
,
61
,
11.9
,
434
,
37
,
16
),
new
Desert
(
'Jelly bean with milk'
,
478
,
2.4
,
106
,
8.0
,
157
,
30
,
0
),
new
Des
s
ert
(
'Jelly bean with milk'
,
478
,
2.4
,
106
,
8.0
,
157
,
30
,
0
),
new
Desert
(
'Lollipop with milk'
,
495
,
2.6
,
110
,
8.0
,
145
,
30
,
2
),
new
Des
s
ert
(
'Lollipop with milk'
,
495
,
2.6
,
110
,
8.0
,
145
,
30
,
2
),
new
Desert
(
'Honeycomb with milk'
,
511
,
5.6
,
99
,
14.5
,
669
,
30
,
45
),
new
Des
s
ert
(
'Honeycomb with milk'
,
511
,
5.6
,
99
,
14.5
,
669
,
30
,
45
),
new
Desert
(
'Donut with milk'
,
555
,
27.4
,
63
,
12.9
,
433
,
32
,
22
),
new
Des
s
ert
(
'Donut with milk'
,
555
,
27.4
,
63
,
12.9
,
433
,
32
,
22
),
new
Desert
(
'KitKat with milk'
,
621
,
28.4
,
77
,
15.0
,
161
,
42
,
6
),
new
Des
s
ert
(
'KitKat with milk'
,
621
,
28.4
,
77
,
15.0
,
161
,
42
,
6
),
new
Desert
(
'Coconut slice and frozen yogurt'
,
318
,
21.0
,
31
,
5.5
,
96
,
14
,
7
),
new
Des
s
ert
(
'Coconut slice and frozen yogurt'
,
318
,
21.0
,
31
,
5.5
,
96
,
14
,
7
),
new
Desert
(
'Coconut slice and ice cream sandwich'
,
396
,
24.0
,
44
,
5.8
,
138
,
8
,
7
),
new
Des
s
ert
(
'Coconut slice and ice cream sandwich'
,
396
,
24.0
,
44
,
5.8
,
138
,
8
,
7
),
new
Desert
(
'Coconut slice and eclair'
,
421
,
31.0
,
31
,
7.5
,
346
,
6
,
13
),
new
Des
s
ert
(
'Coconut slice and eclair'
,
421
,
31.0
,
31
,
7.5
,
346
,
6
,
13
),
new
Desert
(
'Coconut slice and cupcake'
,
464
,
18.7
,
74
,
5.8
,
422
,
3
,
14
),
new
Des
s
ert
(
'Coconut slice and cupcake'
,
464
,
18.7
,
74
,
5.8
,
422
,
3
,
14
),
new
Desert
(
'Coconut slice and gingerbread'
,
515
,
31.0
,
56
,
5.4
,
316
,
7
,
22
),
new
Des
s
ert
(
'Coconut slice and gingerbread'
,
515
,
31.0
,
56
,
5.4
,
316
,
7
,
22
),
new
Desert
(
'Coconut slice and jelly bean'
,
534
,
15.0
,
101
,
1.5
,
59
,
0
,
6
),
new
Des
s
ert
(
'Coconut slice and jelly bean'
,
534
,
15.0
,
101
,
1.5
,
59
,
0
,
6
),
new
Desert
(
'Coconut slice and lollipop'
,
551
,
15.2
,
105
,
1.5
,
47
,
0
,
8
),
new
Des
s
ert
(
'Coconut slice and lollipop'
,
551
,
15.2
,
105
,
1.5
,
47
,
0
,
8
),
new
Desert
(
'Coconut slice and honeycomb'
,
567
,
18.2
,
94
,
8.0
,
571
,
0
,
51
),
new
Des
s
ert
(
'Coconut slice and honeycomb'
,
567
,
18.2
,
94
,
8.0
,
571
,
0
,
51
),
new
Desert
(
'Coconut slice and donut'
,
611
,
40.0
,
58
,
6.4
,
335
,
2
,
28
),
new
Des
s
ert
(
'Coconut slice and donut'
,
611
,
40.0
,
58
,
6.4
,
335
,
2
,
28
),
new
Desert
(
'Coconut slice and KitKat'
,
677
,
41.0
,
72
,
8.5
,
63
,
12
,
12
),
new
Des
s
ert
(
'Coconut slice and KitKat'
,
677
,
41.0
,
72
,
8.5
,
63
,
12
,
12
),
];
];
void
_sort
<
T
>(
Comparable
<
T
>
getField
(
Desert
d
),
bool
ascending
)
{
void
_sort
<
T
>(
Comparable
<
T
>
getField
(
Des
s
ert
d
),
bool
ascending
)
{
_des
erts
.
sort
((
Desert
a
,
De
sert
b
)
{
_des
serts
.
sort
((
Dessert
a
,
Des
sert
b
)
{
if
(!
ascending
)
{
if
(!
ascending
)
{
final
Desert
c
=
a
;
final
Des
s
ert
c
=
a
;
a
=
b
;
a
=
b
;
b
=
c
;
b
=
c
;
}
}
...
@@ -96,35 +96,35 @@ class DesertDataSource extends DataTableSource {
...
@@ -96,35 +96,35 @@ class DesertDataSource extends DataTableSource {
@override
@override
DataRow
getRow
(
int
index
)
{
DataRow
getRow
(
int
index
)
{
assert
(
index
>=
0
);
assert
(
index
>=
0
);
if
(
index
>=
_deserts
.
length
)
if
(
index
>=
_des
s
erts
.
length
)
return
null
;
return
null
;
final
Des
ert
desert
=
_de
serts
[
index
];
final
Des
sert
dessert
=
_des
serts
[
index
];
return
new
DataRow
.
byIndex
(
return
new
DataRow
.
byIndex
(
index:
index
,
index:
index
,
selected:
desert
.
selected
,
selected:
des
s
ert
.
selected
,
onSelectChanged:
(
bool
value
)
{
onSelectChanged:
(
bool
value
)
{
if
(
desert
.
selected
!=
value
)
{
if
(
des
s
ert
.
selected
!=
value
)
{
_selectedCount
+=
value
?
1
:
-
1
;
_selectedCount
+=
value
?
1
:
-
1
;
assert
(
_selectedCount
>=
0
);
assert
(
_selectedCount
>=
0
);
desert
.
selected
=
value
;
des
s
ert
.
selected
=
value
;
notifyListeners
();
notifyListeners
();
}
}
},
},
cells:
<
DataCell
>[
cells:
<
DataCell
>[
new
DataCell
(
new
Text
(
'
${desert.name}
'
)),
new
DataCell
(
new
Text
(
'
${des
s
ert.name}
'
)),
new
DataCell
(
new
Text
(
'
${desert.calories}
'
)),
new
DataCell
(
new
Text
(
'
${des
s
ert.calories}
'
)),
new
DataCell
(
new
Text
(
'
${desert.fat.toStringAsFixed(1)}
'
)),
new
DataCell
(
new
Text
(
'
${des
s
ert.fat.toStringAsFixed(1)}
'
)),
new
DataCell
(
new
Text
(
'
${desert.carbs}
'
)),
new
DataCell
(
new
Text
(
'
${des
s
ert.carbs}
'
)),
new
DataCell
(
new
Text
(
'
${desert.protein.toStringAsFixed(1)}
'
)),
new
DataCell
(
new
Text
(
'
${des
s
ert.protein.toStringAsFixed(1)}
'
)),
new
DataCell
(
new
Text
(
'
${desert.sodium}
'
)),
new
DataCell
(
new
Text
(
'
${des
s
ert.sodium}
'
)),
new
DataCell
(
new
Text
(
'
${desert.calcium}
%'
)),
new
DataCell
(
new
Text
(
'
${des
s
ert.calcium}
%'
)),
new
DataCell
(
new
Text
(
'
${desert.iron}
%'
)),
new
DataCell
(
new
Text
(
'
${des
s
ert.iron}
%'
)),
]
]
);
);
}
}
@override
@override
int
get
rowCount
=>
_deserts
.
length
;
int
get
rowCount
=>
_des
s
erts
.
length
;
@override
@override
bool
get
isRowCountApproximate
=>
false
;
bool
get
isRowCountApproximate
=>
false
;
...
@@ -133,9 +133,9 @@ class DesertDataSource extends DataTableSource {
...
@@ -133,9 +133,9 @@ class DesertDataSource extends DataTableSource {
int
get
selectedRowCount
=>
_selectedCount
;
int
get
selectedRowCount
=>
_selectedCount
;
void
_selectAll
(
bool
checked
)
{
void
_selectAll
(
bool
checked
)
{
for
(
Des
ert
desert
in
_de
serts
)
for
(
Des
sert
dessert
in
_des
serts
)
desert
.
selected
=
checked
;
des
s
ert
.
selected
=
checked
;
_selectedCount
=
checked
?
_deserts
.
length
:
0
;
_selectedCount
=
checked
?
_des
s
erts
.
length
:
0
;
notifyListeners
();
notifyListeners
();
}
}
}
}
...
@@ -151,10 +151,10 @@ class _DataTableDemoState extends State<DataTableDemo> {
...
@@ -151,10 +151,10 @@ class _DataTableDemoState extends State<DataTableDemo> {
int
_rowsPerPage
=
PaginatedDataTable
.
defaultRowsPerPage
;
int
_rowsPerPage
=
PaginatedDataTable
.
defaultRowsPerPage
;
int
_sortColumnIndex
;
int
_sortColumnIndex
;
bool
_sortAscending
=
true
;
bool
_sortAscending
=
true
;
Des
ertDataSource
_desertsDataSource
=
new
De
sertDataSource
();
Des
sertDataSource
_dessertsDataSource
=
new
Des
sertDataSource
();
void
_sort
<
T
>(
Comparable
<
T
>
getField
(
Desert
d
),
int
columnIndex
,
bool
ascending
)
{
void
_sort
<
T
>(
Comparable
<
T
>
getField
(
Des
s
ert
d
),
int
columnIndex
,
bool
ascending
)
{
_desertsDataSource
.
_sort
<
T
>(
getField
,
ascending
);
_des
s
ertsDataSource
.
_sort
<
T
>(
getField
,
ascending
);
setState
(()
{
setState
(()
{
_sortColumnIndex
=
columnIndex
;
_sortColumnIndex
=
columnIndex
;
_sortAscending
=
ascending
;
_sortAscending
=
ascending
;
...
@@ -174,51 +174,51 @@ class _DataTableDemoState extends State<DataTableDemo> {
...
@@ -174,51 +174,51 @@ class _DataTableDemoState extends State<DataTableDemo> {
onRowsPerPageChanged:
(
int
value
)
{
setState
(()
{
_rowsPerPage
=
value
;
});
},
onRowsPerPageChanged:
(
int
value
)
{
setState
(()
{
_rowsPerPage
=
value
;
});
},
sortColumnIndex:
_sortColumnIndex
,
sortColumnIndex:
_sortColumnIndex
,
sortAscending:
_sortAscending
,
sortAscending:
_sortAscending
,
onSelectAll:
_desertsDataSource
.
_selectAll
,
onSelectAll:
_des
s
ertsDataSource
.
_selectAll
,
columns:
<
DataColumn
>[
columns:
<
DataColumn
>[
new
DataColumn
(
new
DataColumn
(
label:
new
Text
(
'Dessert (100g serving)'
),
label:
new
Text
(
'Dessert (100g serving)'
),
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
String
>((
Desert
d
)
=>
d
.
name
,
columnIndex
,
ascending
)
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
String
>((
Des
s
ert
d
)
=>
d
.
name
,
columnIndex
,
ascending
)
),
),
new
DataColumn
(
new
DataColumn
(
label:
new
Text
(
'Calories'
),
label:
new
Text
(
'Calories'
),
tooltip:
'The total amount of food energy in the given serving size.'
,
tooltip:
'The total amount of food energy in the given serving size.'
,
numeric:
true
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Desert
d
)
=>
d
.
calories
,
columnIndex
,
ascending
)
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Des
s
ert
d
)
=>
d
.
calories
,
columnIndex
,
ascending
)
),
),
new
DataColumn
(
new
DataColumn
(
label:
new
Text
(
'Fat (g)'
),
label:
new
Text
(
'Fat (g)'
),
numeric:
true
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Desert
d
)
=>
d
.
fat
,
columnIndex
,
ascending
)
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Des
s
ert
d
)
=>
d
.
fat
,
columnIndex
,
ascending
)
),
),
new
DataColumn
(
new
DataColumn
(
label:
new
Text
(
'Carbs (g)'
),
label:
new
Text
(
'Carbs (g)'
),
numeric:
true
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Desert
d
)
=>
d
.
carbs
,
columnIndex
,
ascending
)
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Des
s
ert
d
)
=>
d
.
carbs
,
columnIndex
,
ascending
)
),
),
new
DataColumn
(
new
DataColumn
(
label:
new
Text
(
'Protein (g)'
),
label:
new
Text
(
'Protein (g)'
),
numeric:
true
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Desert
d
)
=>
d
.
protein
,
columnIndex
,
ascending
)
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Des
s
ert
d
)
=>
d
.
protein
,
columnIndex
,
ascending
)
),
),
new
DataColumn
(
new
DataColumn
(
label:
new
Text
(
'Sodium (mg)'
),
label:
new
Text
(
'Sodium (mg)'
),
numeric:
true
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Desert
d
)
=>
d
.
sodium
,
columnIndex
,
ascending
)
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Des
s
ert
d
)
=>
d
.
sodium
,
columnIndex
,
ascending
)
),
),
new
DataColumn
(
new
DataColumn
(
label:
new
Text
(
'Calcium (%)'
),
label:
new
Text
(
'Calcium (%)'
),
tooltip:
'The amount of calcium as a percentage of the recommended daily amount.'
,
tooltip:
'The amount of calcium as a percentage of the recommended daily amount.'
,
numeric:
true
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Desert
d
)
=>
d
.
calcium
,
columnIndex
,
ascending
)
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Des
s
ert
d
)
=>
d
.
calcium
,
columnIndex
,
ascending
)
),
),
new
DataColumn
(
new
DataColumn
(
label:
new
Text
(
'Iron (%)'
),
label:
new
Text
(
'Iron (%)'
),
numeric:
true
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Desert
d
)
=>
d
.
iron
,
columnIndex
,
ascending
)
onSort:
(
int
columnIndex
,
bool
ascending
)
=>
_sort
<
num
>((
Des
s
ert
d
)
=>
d
.
iron
,
columnIndex
,
ascending
)
),
),
],
],
source
:
_desertsDataSource
source
:
_des
s
ertsDataSource
)
)
]
]
)
)
...
...
packages/flutter/lib/src/material/data_table.dart
View file @
bf296f71
...
@@ -219,10 +219,11 @@ class DataCell {
...
@@ -219,10 +219,11 @@ class DataCell {
///
///
/// See also:
/// See also:
///
///
/// * [DataColumn]
/// * [DataColumn], which describes a column in the data table.
/// * [DataRow]
/// * [DataRow], which contains the data for a row in the data table.
/// * [DataCell]
/// * [DataCell], which contains the data for a single cell in the data table.
/// * [PaginatedDataTable]
/// * [PaginatedDataTable], which shows part of the data in a data table and
/// provides controls for paging through the remainder of the data.
/// * <https://material.google.com/components/data-tables.html>
/// * <https://material.google.com/components/data-tables.html>
class
DataTable
extends
StatelessWidget
{
class
DataTable
extends
StatelessWidget
{
/// Creates a widget describing a data table.
/// Creates a widget describing a data table.
...
...
packages/flutter/lib/src/material/paginated_data_table.dart
View file @
bf296f71
...
@@ -22,8 +22,18 @@ import 'icons.dart';
...
@@ -22,8 +22,18 @@ import 'icons.dart';
import
'progress_indicator.dart'
;
import
'progress_indicator.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
/// A wrapper for [DataTable] that obtains data lazily from a [DataTableSource]
/// A material design data table that shows data using multiple pages.
/// and displays it one page at a time. The widget is presented as a [Card].
///
/// A paginated data table shows [rowsPerPage] rows of data per page and
/// provies controls for showing other pages.
///
/// Data is read lazily from from a [DataTableSource]. The widget is presented
/// as a [Card].
///
/// See also:
///
/// * [DataTable], which is not paginated.
/// * <https://material.io/guidelines/components/data-tables.html#data-tables-tables-within-cards>
class
PaginatedDataTable
extends
StatefulWidget
{
class
PaginatedDataTable
extends
StatefulWidget
{
/// Creates a widget describing a paginated [DataTable] on a [Card].
/// Creates a widget describing a paginated [DataTable] on a [Card].
///
///
...
...
packages/flutter/test/material/data_table_test.dart
0 → 100644
View file @
bf296f71
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
class
Dessert
{
Dessert
(
this
.
name
,
this
.
calories
,
this
.
fat
,
this
.
carbs
,
this
.
protein
,
this
.
sodium
,
this
.
calcium
,
this
.
iron
);
final
String
name
;
final
int
calories
;
final
double
fat
;
final
int
carbs
;
final
double
protein
;
final
int
sodium
;
final
int
calcium
;
final
int
iron
;
}
final
List
<
Dessert
>
kDesserts
=
<
Dessert
>[
new
Dessert
(
'Frozen yogurt'
,
159
,
6.0
,
24
,
4.0
,
87
,
14
,
1
),
new
Dessert
(
'Ice cream sandwich'
,
237
,
9.0
,
37
,
4.3
,
129
,
8
,
1
),
new
Dessert
(
'Eclair'
,
262
,
16.0
,
24
,
6.0
,
337
,
6
,
7
),
new
Dessert
(
'Cupcake'
,
305
,
3.7
,
67
,
4.3
,
413
,
3
,
8
),
new
Dessert
(
'Gingerbread'
,
356
,
16.0
,
49
,
3.9
,
327
,
7
,
16
),
new
Dessert
(
'Jelly bean'
,
375
,
0.0
,
94
,
0.0
,
50
,
0
,
0
),
new
Dessert
(
'Lollipop'
,
392
,
0.2
,
98
,
0.0
,
38
,
0
,
2
),
new
Dessert
(
'Honeycomb'
,
408
,
3.2
,
87
,
6.5
,
562
,
0
,
45
),
new
Dessert
(
'Donut'
,
452
,
25.0
,
51
,
4.9
,
326
,
2
,
22
),
new
Dessert
(
'KitKat'
,
518
,
26.0
,
65
,
7.0
,
54
,
12
,
6
),
];
void
main
(
)
{
testWidgets
(
'DataTable control test'
,
(
WidgetTester
tester
)
async
{
List
<
String
>
log
=
<
String
>[];
Widget
buildTable
({
int
sortColumnIndex
,
bool
sortAscending:
true
})
{
return
new
DataTable
(
sortColumnIndex:
sortColumnIndex
,
sortAscending:
sortAscending
,
onSelectAll:
(
bool
value
)
{
log
.
add
(
'select-all:
$value
'
);
},
columns:
<
DataColumn
>[
new
DataColumn
(
label:
new
Text
(
'Name'
),
tooltip:
'Name'
,
),
new
DataColumn
(
label:
new
Text
(
'Calories'
),
tooltip:
'Calories'
,
numeric:
true
,
onSort:
(
int
columnIndex
,
bool
ascending
)
{
log
.
add
(
'column-sort:
$columnIndex
$ascending
'
);
}
),
],
rows:
kDesserts
.
map
((
Dessert
dessert
)
{
return
new
DataRow
(
key:
new
Key
(
dessert
.
name
),
onSelectChanged:
(
bool
selected
)
{
log
.
add
(
'row-selected:
${dessert.name}
'
);
},
cells:
<
DataCell
>[
new
DataCell
(
new
Text
(
dessert
.
name
),
),
new
DataCell
(
new
Text
(
'
${dessert.calories}
'
),
showEditIcon:
true
,
onTap:
()
{
log
.
add
(
'cell-tap:
${dessert.calories}
'
);
},
),
],
);
}).
toList
(),
);
}
await
tester
.
pumpWidget
(
new
MaterialApp
(
home:
new
Material
(
child:
buildTable
())
));
await
tester
.
tap
(
find
.
byType
(
Checkbox
).
first
);
expect
(
log
,
<
String
>[
'select-all: true'
]);
log
.
clear
();
await
tester
.
tap
(
find
.
text
(
'Cupcake'
));
expect
(
log
,
<
String
>[
'row-selected: Cupcake'
]);
log
.
clear
();
await
tester
.
tap
(
find
.
text
(
'Calories'
));
expect
(
log
,
<
String
>[
'column-sort: 1 true'
]);
log
.
clear
();
await
tester
.
pumpWidget
(
new
MaterialApp
(
home:
new
Material
(
child:
buildTable
(
sortColumnIndex:
1
))
));
await
tester
.
pumpUntilNoTransientCallbacks
(
const
Duration
(
milliseconds:
200
));
await
tester
.
tap
(
find
.
text
(
'Calories'
));
expect
(
log
,
<
String
>[
'column-sort: 1 false'
]);
log
.
clear
();
await
tester
.
pumpWidget
(
new
MaterialApp
(
home:
new
Material
(
child:
buildTable
(
sortColumnIndex:
1
,
sortAscending:
false
))
));
await
tester
.
pumpUntilNoTransientCallbacks
(
const
Duration
(
milliseconds:
200
));
await
tester
.
tap
(
find
.
text
(
'375'
));
expect
(
log
,
<
String
>[
'cell-tap: 375'
]);
log
.
clear
();
await
tester
.
tap
(
find
.
byType
(
Checkbox
).
last
);
expect
(
log
,
<
String
>[
'row-selected: KitKat'
]);
log
.
clear
();
});
}
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