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
0ff0affb
Unverified
Commit
0ff0affb
authored
May 09, 2022
by
Aman Verma
Committed by
GitHub
May 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose controller for PaginatedDataTable (#100005)
parent
89f755c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
1 deletion
+97
-1
paginated_data_table.dart
packages/flutter/lib/src/material/paginated_data_table.dart
+15
-1
paginated_data_table_test.dart
...ages/flutter/test/material/paginated_data_table_test.dart
+82
-0
No files found.
packages/flutter/lib/src/material/paginated_data_table.dart
View file @
0ff0affb
...
...
@@ -86,6 +86,8 @@ class PaginatedDataTable extends StatefulWidget {
this
.
arrowHeadColor
,
required
this
.
source
,
this
.
checkboxHorizontalMargin
,
this
.
controller
,
this
.
primary
,
})
:
assert
(
actions
==
null
||
(
actions
!=
null
&&
header
!=
null
)),
assert
(
columns
!=
null
),
assert
(
dragStartBehavior
!=
null
),
...
...
@@ -105,7 +107,11 @@ class PaginatedDataTable extends StatefulWidget {
assert
(
availableRowsPerPage
!=
null
&&
availableRowsPerPage
.
contains
(
rowsPerPage
));
return
true
;
}()),
assert
(
source
!=
null
);
assert
(
source
!=
null
),
assert
(!(
controller
!=
null
&&
(
primary
??
false
)),
'Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. '
'You cannot both set primary to true and pass an explicit controller.'
,
);
/// The table card's optional header.
///
...
...
@@ -237,6 +243,12 @@ class PaginatedDataTable extends StatefulWidget {
/// Defines the color of the arrow heads in the footer.
final
Color
?
arrowHeadColor
;
/// {@macro flutter.widgets.scroll_view.controller}
final
ScrollController
?
controller
;
/// {@macro flutter.widgets.scroll_view.primary}
final
bool
?
primary
;
@override
PaginatedDataTableState
createState
()
=>
PaginatedDataTableState
();
}
...
...
@@ -501,6 +513,8 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
),
SingleChildScrollView
(
scrollDirection:
Axis
.
horizontal
,
primary:
widget
.
primary
,
controller:
widget
.
controller
,
dragStartBehavior:
widget
.
dragStartBehavior
,
child:
ConstrainedBox
(
constraints:
BoxConstraints
(
minWidth:
constraints
.
minWidth
),
...
...
packages/flutter/test/material/paginated_data_table_test.dart
View file @
0ff0affb
...
...
@@ -398,6 +398,7 @@ void main() {
expect
(
find
.
text
(
'Rows per page:'
),
findsOneWidget
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
'Rows per page:'
)).
dx
,
18.0
);
// 14 padding in the footer row, 4 padding from the card
});
testWidgets
(
'PaginatedDataTable custom row height'
,
(
WidgetTester
tester
)
async
{
final
TestDataSource
source
=
TestDataSource
();
...
...
@@ -1043,4 +1044,85 @@ void main() {
await
tester
.
pumpWidget
(
buildFrame
(
overflowBar
));
expect
(
headerX
,
tester
.
getTopLeft
(
find
.
byType
(
ElevatedButton
)).
dx
);
});
testWidgets
(
'PaginatedDataTable can be scrolled using ScrollController'
,
(
WidgetTester
tester
)
async
{
final
TestDataSource
source
=
TestDataSource
();
final
ScrollController
scrollController
=
ScrollController
();
Widget
buildTable
(
TestDataSource
source
)
{
return
Align
(
alignment:
Alignment
.
topLeft
,
child:
SizedBox
(
width:
100
,
child:
PaginatedDataTable
(
controller:
scrollController
,
header:
const
Text
(
'Test table'
),
source
:
source
,
rowsPerPage:
2
,
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Name'
),
tooltip:
'Name'
,
),
DataColumn
(
label:
Text
(
'Calories'
),
tooltip:
'Calories'
,
numeric:
true
,
),
DataColumn
(
label:
Text
(
'Generation'
),
tooltip:
'Generation'
,
),
],
),
),
);
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
buildTable
(
source
),
));
// DataTable uses provided ScrollController
final
Scrollable
bodyScrollView
=
tester
.
widget
(
find
.
byType
(
Scrollable
).
first
);
expect
(
bodyScrollView
.
controller
,
scrollController
);
expect
(
scrollController
.
offset
,
0.0
);
scrollController
.
jumpTo
(
50.0
);
await
tester
.
pumpAndSettle
();
expect
(
scrollController
.
offset
,
50.0
);
});
testWidgets
(
'PaginatedDataTable uses PrimaryScrollController when primary '
,
(
WidgetTester
tester
)
async
{
final
ScrollController
primaryScrollController
=
ScrollController
();
final
TestDataSource
source
=
TestDataSource
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
PrimaryScrollController
(
controller:
primaryScrollController
,
child:
PaginatedDataTable
(
primary:
true
,
header:
const
Text
(
'Test table'
),
source
:
source
,
rowsPerPage:
2
,
columns:
const
<
DataColumn
>[
DataColumn
(
label:
Text
(
'Name'
)),
DataColumn
(
label:
Text
(
'Calories'
),
numeric:
true
),
DataColumn
(
label:
Text
(
'Generation'
)),
],
),
),
)
);
// DataTable uses primaryScrollController
final
Scrollable
bodyScrollView
=
tester
.
widget
(
find
.
byType
(
Scrollable
).
first
);
expect
(
bodyScrollView
.
controller
,
primaryScrollController
);
// Footer does not use primaryScrollController
final
Scrollable
footerScrollView
=
tester
.
widget
(
find
.
byType
(
Scrollable
).
last
);
expect
(
footerScrollView
.
controller
,
null
);
});
}
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