Adds the `iconMargin` parameter to Tab
This commit is contained in:
parent
f2f9d0e4fd
commit
0265cb6849
@ -60,11 +60,14 @@ class Tab extends StatelessWidget {
|
||||
/// Creates a material design [TabBar] tab.
|
||||
///
|
||||
/// At least one of [text], [icon], and [child] must be non-null. The [text]
|
||||
/// and [child] arguments must not be used at the same time.
|
||||
/// and [child] arguments must not be used at the same time. The
|
||||
/// [iconMargin] is only useful when [icon] and either one of [text] or
|
||||
/// [child] is non-null.
|
||||
const Tab({
|
||||
Key key,
|
||||
this.text,
|
||||
this.icon,
|
||||
this.iconMargin = const EdgeInsets.only(bottom: 10.0),
|
||||
this.child,
|
||||
}) : assert(text != null || child != null || icon != null),
|
||||
assert(!(text != null && null != child)), // TODO(goderbauer): https://github.com/dart-lang/sdk/issues/34180
|
||||
@ -85,6 +88,12 @@ class Tab extends StatelessWidget {
|
||||
/// An icon to display as the tab's label.
|
||||
final Widget icon;
|
||||
|
||||
/// The margin added around the tab's icon.
|
||||
///
|
||||
/// Only useful when used in combination with [icon], and either one of
|
||||
/// [text] or [child] is non-null.
|
||||
final EdgeInsetsGeometry iconMargin;
|
||||
|
||||
Widget _buildLabelText() {
|
||||
return child ?? Text(text, softWrap: false, overflow: TextOverflow.fade);
|
||||
}
|
||||
@ -109,7 +118,7 @@ class Tab extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: icon,
|
||||
margin: const EdgeInsets.only(bottom: 10.0),
|
||||
margin: iconMargin,
|
||||
),
|
||||
_buildLabelText(),
|
||||
],
|
||||
|
@ -254,6 +254,30 @@ void main() {
|
||||
expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0));
|
||||
}, skip: isBrowser);
|
||||
|
||||
testWidgets('Tab sizing - icon, iconMargin and text', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(fontFamily: 'Ahem'),
|
||||
home: const Center(
|
||||
child: Material(
|
||||
child: Tab(
|
||||
icon: SizedBox(
|
||||
width: 10.0,
|
||||
height: 10.0,
|
||||
),
|
||||
iconMargin: EdgeInsets.symmetric(
|
||||
horizontal: 100.0,
|
||||
),
|
||||
text: 'x',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.renderObject<RenderParagraph>(find.byType(RichText)).text.style.fontFamily, 'Ahem');
|
||||
expect(tester.getSize(find.byType(Tab)), const Size(210.0, 72.0));
|
||||
}, skip: isBrowser);
|
||||
|
||||
testWidgets('Tab sizing - icon and child', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(theme: ThemeData(fontFamily: 'Ahem'), home: const Center(child: Material(child: Tab(icon: SizedBox(width: 10.0, height: 10.0), child: Text('x'))))),
|
||||
|
Loading…
x
Reference in New Issue
Block a user