Prevent text from overflowing in OutlineButton and OutlinedButton label. (#70872)

This commit is contained in:
Chinmoy 2021-01-06 23:46:12 +05:30 committed by GitHub
parent 29d33cc38e
commit 7a0e3a309f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 2 deletions

View File

@ -310,7 +310,7 @@ class _OutlineButtonWithIcon extends OutlineButton with MaterialButtonWithIconMi
children: <Widget>[ children: <Widget>[
icon, icon,
const SizedBox(width: 8.0), const SizedBox(width: 8.0),
label, Flexible(child: label),
], ],
), ),
); );

View File

@ -345,7 +345,7 @@ class _OutlinedButtonWithIconChild extends StatelessWidget {
final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!; final double gap = scale <= 1 ? 8 : lerpDouble(8, 4, math.min(scale - 1, 1))!;
return Row( return Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[icon, SizedBox(width: gap), label], children: <Widget>[icon, SizedBox(width: gap), Flexible(child: label)],
); );
} }
} }

View File

@ -1222,6 +1222,22 @@ void main() {
expect(box.size, equals(const Size(76, 36))); expect(box.size, equals(const Size(76, 36)));
expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0))); 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) { PhysicalModelLayer _findPhysicalLayer(Element element) {

View File

@ -1212,6 +1212,22 @@ void main() {
); );
expect(paddingWidget.padding, const EdgeInsets.all(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) { PhysicalModelLayer _findPhysicalLayer(Element element) {