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
3ff0beb5
Unverified
Commit
3ff0beb5
authored
Sep 08, 2023
by
Polina Cherkasova
Committed by
GitHub
Sep 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
_TabBarViewState should dispose created instances of PageController. (#134091)
parent
237ddcc3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
64 deletions
+19
-64
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+12
-8
page_selector_test.dart
packages/flutter/test/material/page_selector_test.dart
+5
-40
scrollbar_test.dart
packages/flutter/test/material/scrollbar_test.dart
+1
-8
tabbed_scrollview_warp_test.dart
...es/flutter/test/material/tabbed_scrollview_warp_test.dart
+1
-8
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
3ff0beb5
...
...
@@ -1783,7 +1783,7 @@ class TabBarView extends StatefulWidget {
class
_TabBarViewState
extends
State
<
TabBarView
>
{
TabController
?
_controller
;
late
PageController
_pageController
;
PageController
?
_pageController
;
late
List
<
Widget
>
_childrenWithKey
;
int
?
_currentIndex
;
int
_warpUnderwayCount
=
0
;
...
...
@@ -1825,7 +1825,7 @@ class _TabBarViewState extends State<TabBarView> {
void
_jumpToPage
(
int
page
)
{
_warpUnderwayCount
+=
1
;
_pageController
.
jumpToPage
(
page
);
_pageController
!
.
jumpToPage
(
page
);
_warpUnderwayCount
-=
1
;
}
...
...
@@ -1835,7 +1835,7 @@ class _TabBarViewState extends State<TabBarView> {
required
Curve
curve
,
})
async
{
_warpUnderwayCount
+=
1
;
await
_pageController
.
animateToPage
(
page
,
duration:
duration
,
curve:
curve
);
await
_pageController
!
.
animateToPage
(
page
,
duration:
duration
,
curve:
curve
);
_warpUnderwayCount
-=
1
;
}
...
...
@@ -1850,6 +1850,8 @@ class _TabBarViewState extends State<TabBarView> {
super
.
didChangeDependencies
();
_updateTabController
();
_currentIndex
=
_controller
!.
index
;
// TODO(chunhtai): https://github.com/flutter/flutter/issues/134253
_pageController
?.
dispose
();
_pageController
=
PageController
(
initialPage:
_currentIndex
!,
viewportFraction:
widget
.
viewportFraction
,
...
...
@@ -1877,6 +1879,7 @@ class _TabBarViewState extends State<TabBarView> {
_controller
!.
animation
!.
removeListener
(
_handleTabControllerAnimationTick
);
}
_controller
=
null
;
_pageController
?.
dispose
();
// We don't own the _controller Animation, so it's not disposed here.
super
.
dispose
();
}
...
...
@@ -1897,7 +1900,7 @@ class _TabBarViewState extends State<TabBarView> {
}
void
_warpToCurrentIndex
()
{
if
(!
mounted
||
_pageController
.
page
==
_currentIndex
!.
toDouble
())
{
if
(!
mounted
||
_pageController
!
.
page
==
_currentIndex
!.
toDouble
())
{
return
;
}
...
...
@@ -1957,7 +1960,7 @@ class _TabBarViewState extends State<TabBarView> {
}
void
_syncControllerOffset
()
{
_controller
!.
offset
=
clampDouble
(
_pageController
.
page
!
-
_controller
!.
index
,
-
1.0
,
1.0
);
_controller
!.
offset
=
clampDouble
(
_pageController
!
.
page
!
-
_controller
!.
index
,
-
1.0
,
1.0
);
}
// Called when the PageView scrolls
...
...
@@ -1975,15 +1978,16 @@ class _TabBarViewState extends State<TabBarView> {
}
_scrollUnderwayCount
+=
1
;
final
double
page
=
_pageController
!.
page
!;
if
(
notification
is
ScrollUpdateNotification
&&
!
_controller
!.
indexIsChanging
)
{
final
bool
pageChanged
=
(
_pageController
.
page
!
-
_controller
!.
index
).
abs
()
>
1.0
;
final
bool
pageChanged
=
(
page
-
_controller
!.
index
).
abs
()
>
1.0
;
if
(
pageChanged
)
{
_controller
!.
index
=
_pageController
.
page
!
.
round
();
_controller
!.
index
=
page
.
round
();
_currentIndex
=
_controller
!.
index
;
}
_syncControllerOffset
();
}
else
if
(
notification
is
ScrollEndNotification
)
{
_controller
!.
index
=
_pageController
.
page
!
.
round
();
_controller
!.
index
=
page
.
round
();
_currentIndex
=
_controller
!.
index
;
if
(!
_controller
!.
indexIsChanging
)
{
_syncControllerOffset
();
...
...
packages/flutter/test/material/page_selector_test.dart
View file @
3ff0beb5
...
...
@@ -84,14 +84,7 @@ void main() {
await
tester
.
pump
();
expect
(
tabController
.
index
,
2
);
expect
(
indicatorColors
(
tester
),
const
<
Color
>[
kUnselectedColor
,
kUnselectedColor
,
kSelectedColor
]);
},
// TODO(someone): remove after fixing
// https://github.com/flutter/flutter/issues/133755
leakTrackingTestConfig:
const
LeakTrackingTestConfig
(
notDisposedAllowList:
<
String
,
int
?>{
'PageController'
:
1
,
},
));
});
testWidgetsWithLeakTracking
(
'PageSelector responds correctly to TabController.animateTo()'
,
(
WidgetTester
tester
)
async
{
final
TabController
tabController
=
TabController
(
...
...
@@ -134,14 +127,7 @@ void main() {
await
tester
.
pumpAndSettle
();
expect
(
tabController
.
index
,
2
);
expect
(
indicatorColors
(
tester
),
const
<
Color
>[
kUnselectedColor
,
kUnselectedColor
,
kSelectedColor
]);
},
// TODO(someone): remove after fixing
// https://github.com/flutter/flutter/issues/133755
leakTrackingTestConfig:
const
LeakTrackingTestConfig
(
notDisposedAllowList:
<
String
,
int
?>{
'PageController'
:
1
,
},
));
});
testWidgetsWithLeakTracking
(
'PageSelector responds correctly to TabBarView drags'
,
(
WidgetTester
tester
)
async
{
final
TabController
tabController
=
TabController
(
...
...
@@ -199,14 +185,7 @@ void main() {
await
tester
.
fling
(
find
.
byType
(
TabBarView
),
const
Offset
(
100.0
,
0.0
),
1000.0
);
await
tester
.
pumpAndSettle
();
expect
(
indicatorColors
(
tester
),
const
<
Color
>[
kUnselectedColor
,
kSelectedColor
,
kUnselectedColor
]);
},
// TODO(someone): remove after fixing
// https://github.com/flutter/flutter/issues/133755
leakTrackingTestConfig:
const
LeakTrackingTestConfig
(
notDisposedAllowList:
<
String
,
int
?>{
'PageController'
:
1
,
},
));
});
testWidgetsWithLeakTracking
(
'PageSelector indicatorColors'
,
(
WidgetTester
tester
)
async
{
const
Color
kRed
=
Color
(
0xFFFF0000
);
...
...
@@ -225,14 +204,7 @@ void main() {
tabController
.
index
=
0
;
await
tester
.
pumpAndSettle
();
expect
(
indicatorColors
(
tester
),
const
<
Color
>[
kBlue
,
kRed
,
kRed
]);
},
// TODO(someone): remove after fixing
// https://github.com/flutter/flutter/issues/133755
leakTrackingTestConfig:
const
LeakTrackingTestConfig
(
notDisposedAllowList:
<
String
,
int
?>{
'PageController'
:
1
,
},
));
});
testWidgets
(
'PageSelector indicatorSize'
,
(
WidgetTester
tester
)
async
{
final
TabController
tabController
=
TabController
(
...
...
@@ -299,12 +271,5 @@ void main() {
for
(
final
TabPageSelectorIndicator
indicator
in
indicators
)
{
expect
(
indicator
.
borderStyle
,
BorderStyle
.
solid
);
}
},
// TODO(someone): remove after fixing
// https://github.com/flutter/flutter/issues/133755
leakTrackingTestConfig:
const
LeakTrackingTestConfig
(
notDisposedAllowList:
<
String
,
int
?>{
'PageController'
:
1
,
},
));
});
}
packages/flutter/test/material/scrollbar_test.dart
View file @
3ff0beb5
...
...
@@ -1834,14 +1834,7 @@ void main() {
);
scrollController
.
dispose
();
},
// TODO(someone): remove after fixing
// https://github.com/flutter/flutter/issues/133755
leakTrackingTestConfig:
const
LeakTrackingTestConfig
(
notDisposedAllowList:
<
String
,
int
?>{
'PageController'
:
2
,
},
));
});
testWidgetsWithLeakTracking
(
'Scrollbar scrollOrientation works correctly'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
scrollController
=
ScrollController
();
...
...
packages/flutter/test/material/tabbed_scrollview_warp_test.dart
View file @
3ff0beb5
...
...
@@ -81,12 +81,5 @@ void main() {
// should not crash.
await
tester
.
tap
(
find
.
text
(
'Tab 2'
));
await
tester
.
pumpAndSettle
();
},
// TODO(someone): remove after fixing
// https://github.com/flutter/flutter/issues/133755
leakTrackingTestConfig:
const
LeakTrackingTestConfig
(
notDisposedAllowList:
<
String
,
int
?>{
'PageController'
:
1
,
},
));
});
}
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