@@ -703,6 +703,7 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
703
703
required TextBaseline textBaseline,
704
704
required bool isFocused,
705
705
required bool expands,
706
+ required bool material3,
706
707
TextAlignVertical ? textAlignVertical,
707
708
}) : assert (decoration != null ),
708
709
assert (textDirection != null ),
@@ -713,7 +714,8 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
713
714
_textBaseline = textBaseline,
714
715
_textAlignVertical = textAlignVertical,
715
716
_isFocused = isFocused,
716
- _expands = expands;
717
+ _expands = expands,
718
+ _material3 = material3;
717
719
718
720
static const double subtextGap = 8.0 ;
719
721
@@ -831,6 +833,16 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
831
833
markNeedsLayout ();
832
834
}
833
835
836
+ bool get material3 => _material3;
837
+ bool _material3 = false ;
838
+ set material3 (bool value) {
839
+ if (_material3 == value) {
840
+ return ;
841
+ }
842
+ _material3 = value;
843
+ markNeedsLayout ();
844
+ }
845
+
834
846
// Indicates that the decoration should be aligned to accommodate an outline
835
847
// border.
836
848
bool get _isOutlineAligned {
@@ -1473,18 +1485,26 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
1473
1485
// _BorderContainer's x and is independent of label's x.
1474
1486
switch (textDirection) {
1475
1487
case TextDirection .rtl:
1476
- decoration.borderGap.start = lerpDouble (labelX + _boxSize (label).width,
1477
- _boxSize (container).width / 2.0 + floatWidth / 2.0 ,
1478
- floatAlign);
1488
+ double offsetToPrefixIcon = 0.0 ;
1489
+ if (prefixIcon != null && ! decoration.alignLabelWithHint) {
1490
+ offsetToPrefixIcon = material3 ? _boxSize (prefixIcon).width - left : 0 ;
1491
+ }
1492
+ decoration.borderGap.start = lerpDouble (labelX + _boxSize (label).width + offsetToPrefixIcon,
1493
+ _boxSize (container).width / 2.0 + floatWidth / 2.0 ,
1494
+ floatAlign);
1479
1495
1480
1496
break ;
1481
1497
case TextDirection .ltr:
1482
1498
// The value of _InputBorderGap.start is relative to the origin of the
1483
1499
// _BorderContainer which is inset by the icon's width. Although, when
1484
1500
// floating label is centered, it's already relative to _BorderContainer.
1485
- decoration.borderGap.start = lerpDouble (labelX - _boxSize (icon).width,
1486
- _boxSize (container).width / 2.0 - floatWidth / 2.0 ,
1487
- floatAlign);
1501
+ double offsetToPrefixIcon = 0.0 ;
1502
+ if (prefixIcon != null && ! decoration.alignLabelWithHint) {
1503
+ offsetToPrefixIcon = material3 ? (- _boxSize (prefixIcon).width + left) : 0 ;
1504
+ }
1505
+ decoration.borderGap.start = lerpDouble (labelX - _boxSize (icon).width + offsetToPrefixIcon,
1506
+ _boxSize (container).width / 2.0 - floatWidth / 2.0 ,
1507
+ floatAlign);
1488
1508
break ;
1489
1509
}
1490
1510
decoration.borderGap.extent = label! .size.width * _kFinalLabelScale;
@@ -1529,17 +1549,26 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
1529
1549
final double scale = lerpDouble (1.0 , _kFinalLabelScale, t)! ;
1530
1550
final double centeredFloatX = _boxParentData (container! ).offset.dx +
1531
1551
_boxSize (container).width / 2.0 - floatWidth / 2.0 ;
1532
- final double floatStartX;
1552
+ final double startX;
1553
+ double floatStartX;
1533
1554
switch (textDirection) {
1534
1555
case TextDirection .rtl: // origin is on the right
1535
- floatStartX = labelOffset.dx + labelWidth * (1.0 - scale);
1556
+ startX = labelOffset.dx + labelWidth * (1.0 - scale);
1557
+ floatStartX = startX;
1558
+ if (prefixIcon != null && ! decoration.alignLabelWithHint) {
1559
+ floatStartX += material3 ? _boxSize (prefixIcon).width - contentPadding.left : 0.0 ;
1560
+ }
1536
1561
break ;
1537
1562
case TextDirection .ltr: // origin on the left
1538
- floatStartX = labelOffset.dx;
1563
+ startX = labelOffset.dx;
1564
+ floatStartX = startX;
1565
+ if (prefixIcon != null && ! decoration.alignLabelWithHint) {
1566
+ floatStartX += material3 ? - _boxSize (prefixIcon).width + contentPadding.left : 0.0 ;
1567
+ }
1539
1568
break ;
1540
1569
}
1541
1570
final double floatEndX = lerpDouble (floatStartX, centeredFloatX, floatAlign)! ;
1542
- final double dx = lerpDouble (floatStartX , floatEndX, t)! ;
1571
+ final double dx = lerpDouble (startX , floatEndX, t)! ;
1543
1572
final double dy = lerpDouble (0.0 , floatingY - labelOffset.dy, t)! ;
1544
1573
_labelTransform = Matrix4 .identity ()
1545
1574
..translate (dx, labelOffset.dy + dy)
@@ -1662,6 +1691,7 @@ class _Decorator extends RenderObjectWidget with SlottedMultiChildRenderObjectWi
1662
1691
textAlignVertical: textAlignVertical,
1663
1692
isFocused: isFocused,
1664
1693
expands: expands,
1694
+ material3: Theme .of (context).useMaterial3,
1665
1695
);
1666
1696
}
1667
1697
0 commit comments