@@ -1650,4 +1650,71 @@ void main() {
16501650 expect (() => new Tab (icon: new Container (), text: 'foo' , child: new Container ()), throwsAssertionError);
16511651 expect (() => new Tab (text: 'foo' , child: new Container ()), throwsAssertionError);
16521652 });
1653+
1654+
1655+ testWidgets ('TabController changes' , (WidgetTester tester) async {
1656+ // This is a regression test for https://github.com/flutter/flutter/issues/14812
1657+
1658+ Widget buildFrame (TabController controller) {
1659+ return boilerplate (
1660+ child: new Container (
1661+ alignment: Alignment .topLeft,
1662+ child: new TabBar (
1663+ controller: controller,
1664+ tabs: < Tab > [
1665+ const Tab (text: 'LEFT' ),
1666+ const Tab (text: 'RIGHT' ),
1667+ ],
1668+ ),
1669+ ),
1670+ );
1671+ }
1672+
1673+ final TabController controller1 = new TabController (
1674+ vsync: const TestVSync (),
1675+ length: 2 ,
1676+ initialIndex: 0 ,
1677+ );
1678+
1679+ final TabController controller2 = new TabController (
1680+ vsync: const TestVSync (),
1681+ length: 2 ,
1682+ initialIndex: 0 ,
1683+ );
1684+
1685+ await tester.pumpWidget (buildFrame (controller1));
1686+ await tester.pumpWidget (buildFrame (controller2));
1687+ expect (controller1.index, 0 );
1688+ expect (controller2.index, 0 );
1689+
1690+ const double indicatorWeight = 2.0 ;
1691+ final RenderBox tabBarBox = tester.firstRenderObject <RenderBox >(find.byType (TabBar ));
1692+ expect (tabBarBox.size.height, 48.0 ); // 48 = _kTabHeight(46) + indicatorWeight(2.0)
1693+
1694+ final double indicatorY = 48.0 - indicatorWeight / 2.0 ;
1695+ double indicatorLeft = indicatorWeight / 2.0 ;
1696+ double indicatorRight = 400.0 - indicatorWeight / 2.0 ; // 400 = screen_width / 2
1697+ expect (tabBarBox, paints..line (
1698+ strokeWidth: indicatorWeight,
1699+ p1: new Offset (indicatorLeft, indicatorY),
1700+ p2: new Offset (indicatorRight, indicatorY),
1701+ ));
1702+
1703+ await tester.tap (find.text ('RIGHT' ));
1704+ await tester.pumpAndSettle ();
1705+ expect (controller1.index, 0 );
1706+ expect (controller2.index, 1 );
1707+
1708+ // Verify that the TabBar's _IndicatorPainter is now listening to
1709+ // tabController2.
1710+
1711+ indicatorLeft = 400.0 + indicatorWeight / 2.0 ;
1712+ indicatorRight = 800.0 - indicatorWeight / 2.0 ;
1713+ expect (tabBarBox, paints..line (
1714+ strokeWidth: indicatorWeight,
1715+ p1: new Offset (indicatorLeft, indicatorY),
1716+ p2: new Offset (indicatorRight, indicatorY),
1717+ ));
1718+ });
1719+
16531720}
0 commit comments