Prevent text from overflowing in OutlineButton and OutlinedButton label. (#70872)
diff --git a/packages/flutter/lib/src/material/outline_button.dart b/packages/flutter/lib/src/material/outline_button.dart
index 8c920b9..8f6713a 100644
--- a/packages/flutter/lib/src/material/outline_button.dart
+++ b/packages/flutter/lib/src/material/outline_button.dart
@@ -310,7 +310,7 @@
children: <Widget>[
icon,
const SizedBox(width: 8.0),
- label,
+ Flexible(child: label),
],
),
);
diff --git a/packages/flutter/lib/src/material/outlined_button.dart b/packages/flutter/lib/src/material/outlined_button.dart
index 9821228..ad6d0a2 100644
--- a/packages/flutter/lib/src/material/outlined_button.dart
+++ b/packages/flutter/lib/src/material/outlined_button.dart
@@ -345,7 +345,7 @@
final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
return Row(
mainAxisSize: MainAxisSize.min,
- children: <Widget>[icon, SizedBox(width: gap), label],
+ children: <Widget>[icon, SizedBox(width: gap), Flexible(child: label)],
);
}
}
diff --git a/packages/flutter/test/material/outline_button_test.dart b/packages/flutter/test/material/outline_button_test.dart
index 82fc115..301fe26 100644
--- a/packages/flutter/test/material/outline_button_test.dart
+++ b/packages/flutter/test/material/outline_button_test.dart
@@ -1222,6 +1222,22 @@
expect(box.size, equals(const Size(76, 36)));
expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0)));
});
+
+ testWidgets('Text does not overflow in OutlineButton label', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ Directionality(
+ textDirection: TextDirection.ltr,
+ child: MouseRegion(
+ cursor: SystemMouseCursors.forbidden,
+ child: OutlineButton.icon(
+ icon: const Icon(Icons.add),
+ label: const Text('this is a very long text used to check whether an overflow occurs or not'),
+ onPressed: () {},
+ ),
+ ),
+ ),
+ );
+ });
}
PhysicalModelLayer _findPhysicalLayer(Element element) {
diff --git a/packages/flutter/test/material/outlined_button_test.dart b/packages/flutter/test/material/outlined_button_test.dart
index 5210760..25cd729 100644
--- a/packages/flutter/test/material/outlined_button_test.dart
+++ b/packages/flutter/test/material/outlined_button_test.dart
@@ -1212,6 +1212,22 @@
);
expect(paddingWidget.padding, const EdgeInsets.all(22));
});
+
+ testWidgets('Text does not overflow in OutlinedButton label', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ Directionality(
+ textDirection: TextDirection.ltr,
+ child: MouseRegion(
+ cursor: SystemMouseCursors.forbidden,
+ child: OutlinedButton.icon(
+ icon: const Icon(Icons.add),
+ label: const Text('this is a very long text used to check whether an overflow occurs or not'),
+ onPressed: () {},
+ ),
+ ),
+ ),
+ );
+ });
}
PhysicalModelLayer _findPhysicalLayer(Element element) {