From 0265cb68499f91488eb38924184ff0eccb538f54 Mon Sep 17 00:00:00 2001 From: Chen Yumin Date: Mon, 23 Dec 2019 23:37:16 +0000 Subject: [PATCH] Make tab's icon margin configurable (Fix #47363) (#47364) Adds the `iconMargin` parameter to Tab --- packages/flutter/lib/src/material/tabs.dart | 13 ++++++++-- packages/flutter/test/material/tabs_test.dart | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 2f98945b2d..cc159d04aa 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -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: [ Container( child: icon, - margin: const EdgeInsets.only(bottom: 10.0), + margin: iconMargin, ), _buildLabelText(), ], diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index 2d34f5488c..5257aa3125 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -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(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'))))),