@@ -488,36 +488,87 @@ void main() {
488
488
}
489
489
});
490
490
491
- testWidgets ('DropdownButtonFormField with isDense:true does not clip large scale text' , (
491
+ // Regression test for https://github.com/flutter/flutter/issues/159971.
492
+ testWidgets ('DropdownButtonFormField does not clip large scale text' , (
492
493
WidgetTester tester,
493
494
) async {
494
495
final Key buttonKey = UniqueKey ();
495
496
const String value = 'two' ;
497
+ const double scaleFactor = 3.0 ;
498
+
499
+ final List <DropdownMenuItem <String >> dropdownItems =
500
+ menuItems.map <DropdownMenuItem <String >>((String item) {
501
+ return DropdownMenuItem <String >(
502
+ key: ValueKey <String >(item),
503
+ value: item,
504
+ child: Text (item, key: ValueKey <String >('${item }Text' )),
505
+ );
506
+ }).toList ();
507
+
508
+ await tester.pumpWidget (
509
+ TestApp (
510
+ textDirection: TextDirection .ltr,
511
+ child: Builder (
512
+ builder: (BuildContext context) {
513
+ return MediaQuery .withClampedTextScaling (
514
+ minScaleFactor: scaleFactor,
515
+ maxScaleFactor: scaleFactor,
516
+ child: Material (
517
+ child: Center (
518
+ child: DropdownButtonFormField <String >(
519
+ key: buttonKey,
520
+ value: value,
521
+ onChanged: onChanged,
522
+ items: dropdownItems,
523
+ ),
524
+ ),
525
+ ),
526
+ );
527
+ },
528
+ ),
529
+ ),
530
+ );
531
+
532
+ final BuildContext context = tester.element (find.byType (DropdownButton <String >));
533
+ final TextStyle style = Theme .of (context).textTheme.titleMedium! ;
534
+ final double lineHeight = style.fontSize! * style.height! ; // 16 * 1.5 = 24
535
+ final double labelHeight = lineHeight * scaleFactor; // 24 * 3.0 = 72
536
+ const double decorationVerticalPadding = 16.0 ;
537
+ final RenderBox box = tester.renderObject <RenderBox >(find.byType (DropdownButton <String >));
538
+ expect (box.size.height, labelHeight + decorationVerticalPadding);
539
+ });
540
+
541
+ // Regression test for https://github.com/flutter/flutter/issues/159971.
542
+ testWidgets ('DropdownButtonFormField with custom text style does not clip large scale text' , (
543
+ WidgetTester tester,
544
+ ) async {
545
+ final Key buttonKey = UniqueKey ();
546
+ const String value = 'two' ;
547
+ const double scaleFactor = 3.0 ;
548
+ const double fontSize = 22 ;
549
+ const double fontHeight = 1.5 ;
496
550
497
551
await tester.pumpWidget (
498
552
TestApp (
499
553
textDirection: TextDirection .ltr,
500
554
child: Builder (
501
555
builder:
502
556
(BuildContext context) => MediaQuery .withClampedTextScaling (
503
- minScaleFactor: 3.0 ,
504
- maxScaleFactor: 3.0 ,
557
+ minScaleFactor: scaleFactor ,
558
+ maxScaleFactor: scaleFactor ,
505
559
child: Material (
506
560
child: Center (
507
561
child: DropdownButtonFormField <String >(
508
562
key: buttonKey,
509
563
value: value,
510
564
onChanged: onChanged,
565
+ style: const TextStyle (fontSize: fontSize, height: fontHeight),
511
566
items:
512
567
menuItems.map <DropdownMenuItem <String >>((String item) {
513
568
return DropdownMenuItem <String >(
514
569
key: ValueKey <String >(item),
515
570
value: item,
516
- child: Text (
517
- item,
518
- key: ValueKey <String >('${item }Text' ),
519
- style: const TextStyle (fontSize: 20.0 ),
520
- ),
571
+ child: Text (item, key: ValueKey <String >('${item }Text' )),
521
572
);
522
573
}).toList (),
523
574
),
@@ -528,8 +579,11 @@ void main() {
528
579
),
529
580
);
530
581
582
+ const double lineHeight = fontSize * fontHeight; // 22 * 1.5 = 33
583
+ const double labelHeight = lineHeight * scaleFactor; // 33 * 3.0 = 99
584
+ const double decorationVerticalPadding = 16.0 ;
531
585
final RenderBox box = tester.renderObject <RenderBox >(find.byType (DropdownButton <String >));
532
- expect (box.size.height, 64.0 );
586
+ expect (box.size.height, labelHeight + decorationVerticalPadding );
533
587
});
534
588
535
589
testWidgets ('DropdownButtonFormField.isDense is true by default' , (WidgetTester tester) async {
0 commit comments