@@ -67,6 +67,42 @@ class AlwaysKeepAliveState extends State<AlwaysKeepAliveWidget>
6767 }
6868}
6969
70+ class _NestedTabBarContainer extends StatelessWidget {
71+ const _NestedTabBarContainer ({
72+ this .tabController,
73+ });
74+
75+ final TabController tabController;
76+
77+ @override
78+ Widget build (BuildContext context) {
79+ return Container (
80+ color: Colors .blue,
81+ child: Column (
82+ children: < Widget > [
83+ TabBar (
84+ controller: tabController,
85+ tabs: const < Tab > [
86+ Tab (text: 'Yellow' ),
87+ Tab (text: 'Grey' ),
88+ ],
89+ ),
90+ Expanded (
91+ flex: 1 ,
92+ child: TabBarView (
93+ controller: tabController,
94+ children: < Widget > [
95+ Container (color: Colors .yellow),
96+ Container (color: Colors .grey),
97+ ],
98+ ),
99+ )
100+ ],
101+ ),
102+ );
103+ }
104+ }
105+
70106Widget buildFrame ({
71107 Key tabBarKey,
72108 List <String > tabs,
@@ -942,6 +978,51 @@ void main() {
942978 expect (tabController.index, 0 );
943979 });
944980
981+ testWidgets ('Nested TabBarView sets ScrollController pixels to non-null value '
982+ 'when disposed before it is set by the applyViewportDimension' , (WidgetTester tester) async {
983+ // This is a regression test for https://github.com/flutter/flutter/issues/18756
984+ final TabController _mainTabController = TabController (length: 4 , vsync: const TestVSync ());
985+ final TabController _nestedTabController = TabController (length: 2 , vsync: const TestVSync ());
986+
987+ await tester.pumpWidget (
988+ MaterialApp (
989+ home: Scaffold (
990+ appBar: AppBar (
991+ title: const Text ('Exception for Nested Tabs' ),
992+ bottom: TabBar (
993+ controller: _mainTabController,
994+ tabs: const < Widget > [
995+ Tab (icon: Icon (Icons .add), text: 'A' ),
996+ Tab (icon: Icon (Icons .add), text: 'B' ),
997+ Tab (icon: Icon (Icons .add), text: 'C' ),
998+ Tab (icon: Icon (Icons .add), text: 'D' ),
999+ ],
1000+ ),
1001+ ),
1002+ body: TabBarView (
1003+ controller: _mainTabController,
1004+ children: < Widget > [
1005+ Container (color: Colors .red),
1006+ _NestedTabBarContainer (tabController: _nestedTabController),
1007+ Container (color: Colors .green),
1008+ Container (color: Colors .indigo),
1009+ ],
1010+ ),
1011+ ),
1012+ )
1013+ );
1014+
1015+ // expect first tab to be selected
1016+ expect (_mainTabController.index, 0 );
1017+
1018+ // tap on third tab
1019+ await tester.tap (find.text ('C' ));
1020+ await tester.pumpAndSettle ();
1021+
1022+ // expect third tab to be selected without exceptions
1023+ expect (_mainTabController.index, 2 );
1024+ });
1025+
9451026 testWidgets ('TabBarView scrolls end close to a new page with custom physics' , (WidgetTester tester) async {
9461027 final TabController tabController = TabController (
9471028 vsync: const TestVSync (),
0 commit comments