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
Expand all
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
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/material/data_table.dart
View file @
bf296f71
...
...
@@ -219,10 +219,11 @@ class DataCell {
///
/// See also:
///
/// * [DataColumn]
/// * [DataRow]
/// * [DataCell]
/// * [PaginatedDataTable]
/// * [DataColumn], which describes a column in the data table.
/// * [DataRow], which contains the data for a row in the data table.
/// * [DataCell], which contains the data for a single cell in the data table.
/// * [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>
class
DataTable
extends
StatelessWidget
{
/// 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';
import
'progress_indicator.dart'
;
import
'theme.dart'
;
/// A wrapper for [DataTable] that obtains data lazily from a [DataTableSource]
/// and displays it one page at a time. The widget is presented as a [Card].
/// A material design data table that shows data using multiple pages.
///
/// 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
{
/// 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