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 { ...@@ -60,11 +60,14 @@ class Tab extends StatelessWidget {
/// Creates a material design [TabBar] tab. /// Creates a material design [TabBar] tab.
/// ///
/// At least one of [text], [icon], and [child] must be non-null. The [text] /// 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({ const Tab({
Key key, Key key,
this.text, this.text,
this.icon, this.icon,
this.iconMargin = const EdgeInsets.only(bottom: 10.0),
this.child, this.child,
}) : assert(text != null || child != null || icon != null), }) : assert(text != null || child != null || icon != null),
assert(!(text != null && null != child)), // TODO(goderbauer): https://github.com/dart-lang/sdk/issues/34180 assert(!(text != null && null != child)), // TODO(goderbauer): https://github.com/dart-lang/sdk/issues/34180
...@@ -85,6 +88,12 @@ class Tab extends StatelessWidget { ...@@ -85,6 +88,12 @@ class Tab extends StatelessWidget {
/// An icon to display as the tab's label. /// An icon to display as the tab's label.
final Widget icon; 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() { Widget _buildLabelText() {
return child ?? Text(text, softWrap: false, overflow: TextOverflow.fade); return child ?? Text(text, softWrap: false, overflow: TextOverflow.fade);
} }
...@@ -109,7 +118,7 @@ class Tab extends StatelessWidget { ...@@ -109,7 +118,7 @@ class Tab extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Container( Container(
child: icon, child: icon,
margin: const EdgeInsets.only(bottom: 10.0), margin: iconMargin,
), ),
_buildLabelText(), _buildLabelText(),
], ],
......
...@@ -254,6 +254,30 @@ void main() { ...@@ -254,6 +254,30 @@ void main() {
expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0)); expect(tester.getSize(find.byType(Tab)), const Size(14.0, 72.0));
}, skip: isBrowser); }, 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 { testWidgets('Tab sizing - icon and child', (WidgetTester tester) async {
await tester.pumpWidget( 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'))))), 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