Skip to content
GitLab
Menu
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
mirror
flutter
Commits
7b16cbcb
Unverified
Commit
7b16cbcb
authored
1 year ago
by
Gil Nobrega
Committed by
GitHub
1 year ago
Browse files
Options
Download
Email Patches
Plain Diff
Do not animate `TabBarView` if controller is invalid (#123442)
parent
784ebdf2
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/flutter/lib/src/material/tabs.dart
+4
-0
packages/flutter/lib/src/material/tabs.dart
packages/flutter/test/material/tabs_test.dart
+62
-0
packages/flutter/test/material/tabs_test.dart
with
66 additions
and
0 deletions
+66
-0
packages/flutter/lib/src/material/tabs.dart
+
4
-
0
View file @
7b16cbcb
...
...
@@ -1893,6 +1893,10 @@ class _TabBarViewState extends State<TabBarView> {
return
false
;
}
if
(
!
_controllerIsValid
)
{
return
false
;
}
_scrollUnderwayCount
+=
1
;
if
(
notification
is
ScrollUpdateNotification
&&
!
_controller
!.
indexIsChanging
)
{
final
bool
pageChanged
=
(
_pageController
.
page
!
-
_controller
!.
index
)
.
abs
()
>
1.0
;
...
...
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/tabs_test.dart
+
62
-
0
View file @
7b16cbcb
...
...
@@ -3818,6 +3818,68 @@ void main() {
));
});
testWidgets
(
'TabController changes while flinging'
,
(
WidgetTester
tester
)
async
{
// This is a regression test for https://github.com/flutter/flutter/issues/34744
Widget
buildFrame
(
TabController
controller
)
{
return
MaterialApp
(
theme:
ThemeData
(
platform:
TargetPlatform
.
iOS
),
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'tabs'
),
bottom:
TabBar
(
controller:
controller
,
tabs:
<
Tab
>[
const
Tab
(
text:
'A'
),
const
Tab
(
text:
'B'
),
if
(
controller
.
length
==
3
)
const
Tab
(
text:
'C'
),
],
),
),
body:
TabBarView
(
controller:
controller
,
children:
<
Widget
>[
const
Center
(
child:
Text
(
'CHILD A'
)),
const
Center
(
child:
Text
(
'CHILD B'
)),
if
(
controller
.
length
==
3
)
const
Center
(
child:
Text
(
'CHILD C'
)),
],
),
),
);
}
final
TabController
controller1
=
TabController
(
vsync:
const
TestVSync
(),
length:
2
,
);
final
TabController
controller2
=
TabController
(
vsync:
const
TestVSync
(),
length:
3
,
);
expect
(
controller1
.
index
,
0
);
expect
(
controller2
.
index
,
0
);
await
tester
.
pumpWidget
(
buildFrame
(
controller1
));
final
Offset
flingStart
=
tester
.
getCenter
(
find
.
text
(
'CHILD A'
));
await
tester
.
flingFrom
(
flingStart
,
const
Offset
(
-
200.0
,
0.0
),
10000.0
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
// start the fling animation
controller1
.
dispose
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
await
tester
.
pumpWidget
(
buildFrame
(
controller2
));
// replace controller
await
tester
.
flingFrom
(
flingStart
,
const
Offset
(
-
200.0
,
0.0
),
10000.0
);
await
tester
.
pumpAndSettle
();
// finish the fling animation
expect
(
controller1
.
index
,
0
);
expect
(
controller2
.
index
,
1
);
});
testWidgets
(
'TabController changes with different initialIndex'
,
(
WidgetTester
tester
)
async
{
// This is a regression test for https://github.com/flutter/flutter/issues/115917
const
Key
lastTabKey
=
Key
(
'Last Tab'
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Projects
Groups
Snippets