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
12e6ff2c
Unverified
Commit
12e6ff2c
authored
Sep 07, 2023
by
Polina Cherkasova
Committed by
GitHub
Sep 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DropdownRoutePage should dispose the created ScrollController. (#133941)
parent
aca91df6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
21 deletions
+44
-21
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+42
-20
paginated_data_table_test.dart
...ages/flutter/test/material/paginated_data_table_test.dart
+2
-1
No files found.
packages/flutter/lib/src/material/dropdown.dart
View file @
12e6ff2c
...
...
@@ -102,9 +102,11 @@ class _DropdownMenuItemButton<T> extends StatefulWidget {
required
this
.
constraints
,
required
this
.
itemIndex
,
required
this
.
enableFeedback
,
required
this
.
scrollController
,
});
final
_DropdownRoute
<
T
>
route
;
final
ScrollController
scrollController
;
final
EdgeInsets
?
padding
;
final
Rect
buttonRect
;
final
BoxConstraints
constraints
;
...
...
@@ -131,7 +133,7 @@ class _DropdownMenuItemButtonState<T> extends State<_DropdownMenuItemButton<T>>
widget
.
constraints
.
maxHeight
,
widget
.
itemIndex
,
);
widget
.
route
.
scrollController
!
.
animateTo
(
widget
.
scrollController
.
animateTo
(
menuLimits
.
scrollOffset
,
curve:
Curves
.
easeInOut
,
duration:
const
Duration
(
milliseconds:
100
),
...
...
@@ -205,6 +207,7 @@ class _DropdownMenu<T> extends StatefulWidget {
this
.
dropdownColor
,
required
this
.
enableFeedback
,
this
.
borderRadius
,
required
this
.
scrollController
,
});
final
_DropdownRoute
<
T
>
route
;
...
...
@@ -214,6 +217,7 @@ class _DropdownMenu<T> extends StatefulWidget {
final
Color
?
dropdownColor
;
final
bool
enableFeedback
;
final
BorderRadius
?
borderRadius
;
final
ScrollController
scrollController
;
@override
_DropdownMenuState
<
T
>
createState
()
=>
_DropdownMenuState
<
T
>();
...
...
@@ -264,6 +268,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
constraints:
widget
.
constraints
,
itemIndex:
itemIndex
,
enableFeedback:
widget
.
enableFeedback
,
scrollController:
widget
.
scrollController
,
),
];
...
...
@@ -304,7 +309,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
platform:
Theme
.
of
(
context
).
platform
,
),
child:
PrimaryScrollController
(
controller:
widget
.
route
.
scrollController
!
,
controller:
widget
.
scrollController
,
child:
Scrollbar
(
thumbVisibility:
true
,
child:
ListView
(
...
...
@@ -447,7 +452,6 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
final
BorderRadius
?
borderRadius
;
final
List
<
double
>
itemHeights
;
ScrollController
?
scrollController
;
@override
Duration
get
transitionDuration
=>
_kDropdownMenuDuration
;
...
...
@@ -572,7 +576,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
}
}
class
_DropdownRoutePage
<
T
>
extends
State
less
Widget
{
class
_DropdownRoutePage
<
T
>
extends
State
ful
Widget
{
const
_DropdownRoutePage
({
super
.
key
,
required
this
.
route
,
...
...
@@ -603,8 +607,15 @@ class _DropdownRoutePage<T> extends StatelessWidget {
final
BorderRadius
?
borderRadius
;
@override
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasDirectionality
(
context
));
State
<
_DropdownRoutePage
<
T
>>
createState
()
=>
_DropdownRoutePageState
<
T
>();
}
class
_DropdownRoutePageState
<
T
>
extends
State
<
_DropdownRoutePage
<
T
>>
{
late
ScrollController
_scrollSontroller
;
@override
void
initState
(){
super
.
initState
();
// Computing the initialScrollOffset now, before the items have been laid
// out. This only works if the item heights are effectively fixed, i.e. either
...
...
@@ -612,20 +623,25 @@ class _DropdownRoutePage<T> extends StatelessWidget {
// and all of the items' intrinsic heights are less than kMinInteractiveDimension.
// Otherwise the initialScrollOffset is just a rough approximation based on
// treating the items as if their heights were all equal to kMinInteractiveDimension.
if
(
route
.
scrollController
==
null
)
{
final
_MenuLimits
menuLimits
=
route
.
getMenuLimits
(
buttonRect
,
constraints
.
maxHeight
,
selectedIndex
);
route
.
scrollController
=
ScrollController
(
initialScrollOffset:
menuLimits
.
scrollOffset
);
}
final
_MenuLimits
menuLimits
=
widget
.
route
.
getMenuLimits
(
widget
.
buttonRect
,
widget
.
constraints
.
maxHeight
,
widget
.
selectedIndex
);
_scrollSontroller
=
ScrollController
(
initialScrollOffset:
menuLimits
.
scrollOffset
);
}
@override
Widget
build
(
BuildContext
context
)
{
assert
(
debugCheckHasDirectionality
(
context
));
final
TextDirection
?
textDirection
=
Directionality
.
maybeOf
(
context
);
final
Widget
menu
=
_DropdownMenu
<
T
>(
route:
route
,
padding:
padding
.
resolve
(
textDirection
),
buttonRect:
buttonRect
,
constraints:
constraints
,
dropdownColor:
dropdownColor
,
enableFeedback:
enableFeedback
,
borderRadius:
borderRadius
,
route:
widget
.
route
,
padding:
widget
.
padding
.
resolve
(
textDirection
),
buttonRect:
widget
.
buttonRect
,
constraints:
widget
.
constraints
,
dropdownColor:
widget
.
dropdownColor
,
enableFeedback:
widget
.
enableFeedback
,
borderRadius:
widget
.
borderRadius
,
scrollController:
_scrollSontroller
,
);
return
MediaQuery
.
removePadding
(
...
...
@@ -638,16 +654,22 @@ class _DropdownRoutePage<T> extends StatelessWidget {
builder:
(
BuildContext
context
)
{
return
CustomSingleChildLayout
(
delegate:
_DropdownMenuRouteLayout
<
T
>(
buttonRect:
buttonRect
,
route:
route
,
buttonRect:
widget
.
buttonRect
,
route:
widget
.
route
,
textDirection:
textDirection
,
),
child:
capturedThemes
.
wrap
(
menu
),
child:
widget
.
capturedThemes
.
wrap
(
menu
),
);
},
),
);
}
@override
void
dispose
()
{
_scrollSontroller
.
dispose
();
super
.
dispose
();
}
}
// This widget enables _DropdownRoute to look up the sizes of
...
...
packages/flutter/test/material/paginated_data_table_test.dart
View file @
12e6ff2c
...
...
@@ -6,6 +6,7 @@ import 'package:flutter/gestures.dart' show DragStartBehavior;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'
;
import
'data_table_test_utils.dart'
;
...
...
@@ -66,7 +67,7 @@ class TestDataSource extends DataTableSource {
void
main
(
)
{
final
TestWidgetsFlutterBinding
binding
=
TestWidgetsFlutterBinding
.
ensureInitialized
();
testWidgets
(
'PaginatedDataTable paging'
,
(
WidgetTester
tester
)
async
{
testWidgets
WithLeakTracking
(
'PaginatedDataTable paging'
,
(
WidgetTester
tester
)
async
{
final
TestDataSource
source
=
TestDataSource
();
addTearDown
(
source
.
dispose
);
...
...
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