From 64d3647084b69c944342f45cf12326f00abd8138 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 30 Jan 2017 16:11:01 -0800 Subject: [PATCH] Tab crash in complex_layout (#7744) --- dev/benchmarks/complex_layout/lib/main.dart | 28 ++++++++++----------- packages/flutter/lib/src/material/tabs.dart | 7 +++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/dev/benchmarks/complex_layout/lib/main.dart b/dev/benchmarks/complex_layout/lib/main.dart index 5acfecef48..b7303e4ff9 100644 --- a/dev/benchmarks/complex_layout/lib/main.dart +++ b/dev/benchmarks/complex_layout/lib/main.dart @@ -50,16 +50,15 @@ class ComplexLayout extends StatefulWidget { ComplexLayoutState createState() => new ComplexLayoutState(); static ComplexLayoutState of(BuildContext context) => context.ancestorStateOfType(const TypeMatcher()); - } class FancyItemDelegate extends LazyBlockDelegate { @override Widget buildItem(BuildContext context, int index) { if (index % 2 == 0) - return new FancyImageItem(index, key: new Key('Item $index')); + return new FancyImageItem(index, key: new ValueKey(index)); else - return new FancyGalleryItem(index, key: new Key('Item $index')); + return new FancyGalleryItem(index, key: new ValueKey(index)); } @override @@ -84,7 +83,7 @@ class ComplexLayoutState extends State { tooltip: 'Search', onPressed: () { print('Pressed search'); - } + }, ), new TopBarMenu() ] @@ -93,14 +92,13 @@ class ComplexLayoutState extends State { children: [ new Expanded( child: new LazyBlock( - key: new Key('main-scroll'), - delegate: new FancyItemDelegate() + delegate: new FancyItemDelegate(), ) ), - new BottomBar() - ] + new BottomBar(), + ], ), - drawer: new GalleryDrawer() + drawer: new GalleryDrawer(), ); } } @@ -478,7 +476,7 @@ class ItemGalleryBox extends StatelessWidget { child: new TabBarView( children: tabNames.map((String tabName) { return new Container( - key: new Key('Tab $index - $tabName'), + key: new Key(tabName), child: new Padding( padding: new EdgeInsets.all(8.0), child: new Card( @@ -487,10 +485,10 @@ class ItemGalleryBox extends StatelessWidget { new Expanded( child: new Container( decoration: new BoxDecoration( - backgroundColor: Theme.of(context).primaryColor + backgroundColor: Theme.of(context).primaryColor, ), child: new Center( - child: new Text(tabName, style: Theme.of(context).textTheme.headline.copyWith(color: Colors.white)) + child: new Text(tabName, style: Theme.of(context).textTheme.headline.copyWith(color: Colors.white)), ) ) ), @@ -498,16 +496,16 @@ class ItemGalleryBox extends StatelessWidget { children: [ new IconButton( icon: new Icon(Icons.share), - onPressed: () { print('Pressed share'); } + onPressed: () { print('Pressed share'); }, ), new IconButton( icon: new Icon(Icons.event), - onPressed: () { print('Pressed event'); } + onPressed: () { print('Pressed event'); }, ), new Expanded( child: new Padding( padding: new EdgeInsets.only(left: 8.0), - child: new Text('This is item $tabName') + child: new Text('This is item $tabName'), ) ) ] diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 91ab82a65b..918dbca8bf 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -866,6 +866,7 @@ class TabPageSelector extends StatelessWidget { final ColorTween selectedColor = new ColorTween(begin: Colors.transparent, end: color); final ColorTween previousColor = new ColorTween(begin: color, end: Colors.transparent); final TabController tabController = controller ?? DefaultTabController.of(context); + assert(tabController != null); final Animation animation = new CurvedAnimation( parent: tabController.animation, curve: Curves.fastOutSlowIn, @@ -874,11 +875,11 @@ class TabPageSelector extends StatelessWidget { animation: animation, builder: (BuildContext context, Widget child) { return new Semantics( - label: 'Page ${controller.index + 1} of ${controller.length}', + label: 'Page ${tabController.index + 1} of ${tabController.length}', child: new Row( mainAxisSize: MainAxisSize.min, - children: new List.generate(controller.length, (int tabIndex) { - return _buildTabIndicator(tabIndex, controller, selectedColor, previousColor); + children: new List.generate(tabController.length, (int tabIndex) { + return _buildTabIndicator(tabIndex, tabController, selectedColor, previousColor); }).toList(), ), );