Commit 0265cb68 authored by Chen Yumin's avatar Chen Yumin Committed by Justin McCandless

Make tab's icon margin configurable (Fix #47363) (#47364)

Adds the `iconMargin` parameter to Tab
parent f2f9d0e4
......@@ -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'))))),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment