Trailing widget override for ExpansionTile (#11904)
* Trailing widget override for ExpansionTile Fixes #11890 * Add a test * Replaced missing comma
This commit is contained in:
parent
33daa2f982
commit
016f939074
@ -38,6 +38,7 @@ class ExpansionTile extends StatefulWidget {
|
|||||||
this.backgroundColor,
|
this.backgroundColor,
|
||||||
this.onExpansionChanged,
|
this.onExpansionChanged,
|
||||||
this.children: const <Widget>[],
|
this.children: const <Widget>[],
|
||||||
|
this.trailing,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// A widget to display before the title.
|
/// A widget to display before the title.
|
||||||
@ -65,6 +66,9 @@ class ExpansionTile extends StatefulWidget {
|
|||||||
/// The color to display behind the sublist when expanded.
|
/// The color to display behind the sublist when expanded.
|
||||||
final Color backgroundColor;
|
final Color backgroundColor;
|
||||||
|
|
||||||
|
/// A widget to display instead of a rotating arrow icon.
|
||||||
|
final Widget trailing;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ExpansionTileState createState() => new _ExpansionTileState();
|
_ExpansionTileState createState() => new _ExpansionTileState();
|
||||||
}
|
}
|
||||||
@ -145,7 +149,7 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
|
|||||||
style: Theme.of(context).textTheme.subhead.copyWith(color: titleColor),
|
style: Theme.of(context).textTheme.subhead.copyWith(color: titleColor),
|
||||||
child: widget.title,
|
child: widget.title,
|
||||||
),
|
),
|
||||||
trailing: new RotationTransition(
|
trailing: widget.trailing ?? new RotationTransition(
|
||||||
turns: _iconTurns,
|
turns: _iconTurns,
|
||||||
child: const Icon(Icons.expand_more),
|
child: const Icon(Icons.expand_more),
|
||||||
),
|
),
|
||||||
|
@ -103,4 +103,33 @@ void main() {
|
|||||||
await tester.tap(find.text('Sublist'));
|
await tester.tap(find.text('Sublist'));
|
||||||
expect(didChangeOpen, isFalse);
|
expect(didChangeOpen, isFalse);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('trailing override', (WidgetTester tester) async {
|
||||||
|
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
|
||||||
|
'/': (_) {
|
||||||
|
return new Material(
|
||||||
|
child: new SingleChildScrollView(
|
||||||
|
child: new Column(
|
||||||
|
children: <Widget>[
|
||||||
|
const ListTile(title: const Text('Top')),
|
||||||
|
new ExpansionTile(
|
||||||
|
title: const Text('Sublist'),
|
||||||
|
children: <Widget>[
|
||||||
|
const ListTile(title: const Text('0')),
|
||||||
|
const ListTile(title: const Text('1'))
|
||||||
|
],
|
||||||
|
trailing: const Icon(Icons.inbox),
|
||||||
|
),
|
||||||
|
const ListTile(title: const Text('Bottom'))
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await tester.pumpWidget(new MaterialApp(routes: routes));
|
||||||
|
expect(find.byIcon(Icons.inbox), findsOneWidget);
|
||||||
|
expect(find.byIcon(Icons.expand_more), findsNothing);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user