diff --git a/packages/flutter/lib/src/material/expansion_panel.dart b/packages/flutter/lib/src/material/expansion_panel.dart index 7ce98c90fd..7aee797715 100644 --- a/packages/flutter/lib/src/material/expansion_panel.dart +++ b/packages/flutter/lib/src/material/expansion_panel.dart @@ -13,6 +13,32 @@ import 'theme.dart'; const double _kPanelHeaderCollapsedHeight = 48.0; const double _kPanelHeaderExpandedHeight = 64.0; +class _SaltedKey extends LocalKey { + const _SaltedKey(this.salt, this.value); + + final S salt; + final V value; + + @override + bool operator ==(dynamic other) { + if (other.runtimeType != runtimeType) + return false; + final _SaltedKey typedOther = other; + return salt == typedOther.salt + && value == typedOther.value; + } + + @override + int get hashCode => hashValues(runtimeType, salt, value); + + @override + String toString() { + final String saltString = S == String ? '<\'$salt\'>' : '<$salt>'; + final String valueString = V == String ? '<\'$value\'>' : '<$value>'; + return '[$saltString $valueString]'; + } +} + /// Signature for the callback that's called when an [ExpansionPanel] is /// expanded or collapsed. /// @@ -109,7 +135,7 @@ class ExpansionPanelList extends StatelessWidget { for (int i = 0; i < children.length; i += 1) { if (_isChildExpanded(i) && i != 0 && !_isChildExpanded(i - 1)) - items.add(new MaterialGap(key: new ValueKey(i * 2 - 1))); + items.add(new MaterialGap(key: new _SaltedKey(context, i * 2 - 1))); final Row header = new Row( children: [ @@ -144,7 +170,7 @@ class ExpansionPanelList extends StatelessWidget { items.add( new MaterialSlice( - key: new ValueKey(i * 2), + key: new _SaltedKey(context, i * 2), child: new Column( children: [ header, @@ -163,7 +189,7 @@ class ExpansionPanelList extends StatelessWidget { ); if (_isChildExpanded(i) && i != children.length - 1) - items.add(new MaterialGap(key: new ValueKey(i * 2 + 1))); + items.add(new MaterialGap(key: new _SaltedKey(context, i * 2 + 1))); } return new MergeableMaterial( diff --git a/packages/flutter/test/material/expansion_panel_test.dart b/packages/flutter/test/material/expansion_panel_test.dart index 64e16abd89..191763d5dc 100644 --- a/packages/flutter/test/material/expansion_panel_test.dart +++ b/packages/flutter/test/material/expansion_panel_test.dart @@ -71,4 +71,42 @@ void main() { box = tester.renderObject(find.byType(ExpansionPanelList)); expect(box.size.height - oldHeight, greaterThanOrEqualTo(100.0)); // 100 + some margin }); + testWidgets("Multiple Panel List test", (WidgetTester tester) async { + await tester.pumpWidget( + new MaterialApp( + home: new ListView( + children: [ + new ExpansionPanelList( + children: [ + new ExpansionPanel( + headerBuilder: (BuildContext context, bool isExpanded) { + return new Text(isExpanded ? 'B' : 'A'); + }, + body: const SizedBox(height:100.0), + isExpanded: true, + ), + ], + ), + new ExpansionPanelList( + children: [ + new ExpansionPanel( + headerBuilder: (BuildContext context, bool isExpanded){ + return new Text(isExpanded ? 'D' : 'C'); + }, + body: const SizedBox(height:100.0), + isExpanded: true, + ), + ], + ), + ], + ), + ), + ); + await tester.pump(const Duration(milliseconds: 200)); + + expect(find.text('A'), findsNothing); + expect(find.text('B'), findsOneWidget); + expect(find.text('C'), findsNothing); + expect(find.text('D'), findsOneWidget); + }); }