@@ -939,11 +939,21 @@ float _layoutLineBox(RenderBox box, BoxConstraints constraints) {
939
939
_RenderDecorationLayout _layout ( BoxConstraints layoutConstraints ) {
940
940
Dictionary < RenderBox , float > boxToBaseline = new Dictionary < RenderBox , float > ( ) ;
941
941
BoxConstraints boxConstraints = layoutConstraints . loosen ( ) ;
942
- boxToBaseline [ this . prefix ] = this . _layoutLineBox ( this . prefix , boxConstraints ) ;
943
- boxToBaseline [ this . suffix ] = this . _layoutLineBox ( this . suffix , boxConstraints ) ;
944
- boxToBaseline [ this . icon ] = this . _layoutLineBox ( this . icon , boxConstraints ) ;
945
- boxToBaseline [ this . prefixIcon ] = this . _layoutLineBox ( this . prefixIcon , boxConstraints ) ;
946
- boxToBaseline [ this . suffixIcon ] = this . _layoutLineBox ( this . suffixIcon , boxConstraints ) ;
942
+ if ( this . prefix != null ) {
943
+ boxToBaseline [ this . prefix ] = this . _layoutLineBox ( this . prefix , boxConstraints ) ;
944
+ }
945
+ if ( this . suffix != null ) {
946
+ boxToBaseline [ this . suffix ] = this . _layoutLineBox ( this . suffix , boxConstraints ) ;
947
+ }
948
+ if ( this . icon != null ) {
949
+ boxToBaseline [ this . icon ] = this . _layoutLineBox ( this . icon , boxConstraints ) ;
950
+ }
951
+ if ( this . prefixIcon != null ) {
952
+ boxToBaseline [ this . prefixIcon ] = this . _layoutLineBox ( this . prefixIcon , boxConstraints ) ;
953
+ }
954
+ if ( this . suffixIcon != null ) {
955
+ boxToBaseline [ this . suffixIcon ] = this . _layoutLineBox ( this . suffixIcon , boxConstraints ) ;
956
+ }
947
957
948
958
float inputWidth = Math . Max ( 0.0f , this . constraints . maxWidth - (
949
959
_boxSize ( this . icon ) . width
@@ -953,23 +963,33 @@ _RenderDecorationLayout _layout(BoxConstraints layoutConstraints) {
953
963
+ _boxSize ( this . suffix ) . width
954
964
+ _boxSize ( this . suffixIcon ) . width
955
965
+ this . contentPadding . right ) ) ;
956
- boxToBaseline [ this . label ] = this . _layoutLineBox ( this . label ,
957
- boxConstraints . copyWith ( maxWidth : inputWidth )
958
- ) ;
959
- boxToBaseline [ this . hint ] = this . _layoutLineBox ( this . hint ,
960
- boxConstraints . copyWith ( minWidth : inputWidth , maxWidth : inputWidth )
961
- ) ;
962
- boxToBaseline [ this . counter ] = this . _layoutLineBox ( this . counter , boxConstraints ) ;
963
-
964
- boxToBaseline [ this . helperError ] = this . _layoutLineBox ( this . helperError ,
965
- boxConstraints . copyWith (
966
- maxWidth : Math . Max ( 0.0f , boxConstraints . maxWidth
967
- - _boxSize ( this . icon ) . width
968
- - _boxSize ( this . counter ) . width
969
- - this . contentPadding . horizontal
966
+ if ( this . label != null ) {
967
+ boxToBaseline [ this . label ] = this . _layoutLineBox ( this . label ,
968
+ boxConstraints . copyWith ( maxWidth : inputWidth )
969
+ ) ;
970
+ }
971
+
972
+ if ( this . hint != null ) {
973
+ boxToBaseline [ this . hint ] = this . _layoutLineBox ( this . hint ,
974
+ boxConstraints . copyWith ( minWidth : inputWidth , maxWidth : inputWidth )
975
+ ) ;
976
+ }
977
+
978
+ if ( this . counter != null ) {
979
+ boxToBaseline [ this . counter ] = this . _layoutLineBox ( this . counter , boxConstraints ) ;
980
+ }
981
+
982
+ if ( this . helperError != null ) {
983
+ boxToBaseline [ this . helperError ] = this . _layoutLineBox ( this . helperError ,
984
+ boxConstraints . copyWith (
985
+ maxWidth : Math . Max ( 0.0f , boxConstraints . maxWidth
986
+ - _boxSize ( this . icon ) . width
987
+ - _boxSize ( this . counter ) . width
988
+ - this . contentPadding . horizontal
989
+ )
970
990
)
971
- )
972
- ) ;
991
+ ) ;
992
+ }
973
993
974
994
float labelHeight = this . label == null
975
995
? 0
@@ -989,37 +1009,39 @@ _RenderDecorationLayout _layout(BoxConstraints layoutConstraints) {
989
1009
counterHeight ,
990
1010
helperErrorHeight
991
1011
) ;
992
- boxToBaseline [ this . input ] = this . _layoutLineBox ( this . input ,
993
- boxConstraints . deflate ( EdgeInsets . only (
994
- top : this . contentPadding . top + topHeight ,
995
- bottom : this . contentPadding . bottom + bottomHeight
996
- ) ) . copyWith (
997
- minWidth : inputWidth ,
998
- maxWidth : inputWidth
999
- )
1000
- ) ;
1012
+ if ( this . input != null ) {
1013
+ boxToBaseline [ this . input ] = this . _layoutLineBox ( this . input ,
1014
+ boxConstraints . deflate ( EdgeInsets . only (
1015
+ top : this . contentPadding . top + topHeight ,
1016
+ bottom : this . contentPadding . bottom + bottomHeight
1017
+ ) ) . copyWith (
1018
+ minWidth : inputWidth ,
1019
+ maxWidth : inputWidth
1020
+ )
1021
+ ) ;
1022
+ }
1001
1023
1002
1024
// The field can be occupied by a hint or by the input itself
1003
1025
float hintHeight = this . hint == null ? 0 : this . hint . size . height ;
1004
1026
float inputDirectHeight = this . input == null ? 0 : this . input . size . height ;
1005
1027
float inputHeight = Math . Max ( hintHeight , inputDirectHeight ) ;
1006
1028
float inputInternalBaseline = Math . Max (
1007
- boxToBaseline [ this . input ] ,
1008
- boxToBaseline [ this . hint ]
1029
+ boxToBaseline . getOrDefault ( this . input , 0.0f ) ,
1030
+ boxToBaseline . getOrDefault ( this . hint , 0.0f )
1009
1031
) ;
1010
1032
1011
1033
// Calculate the amount that prefix/suffix affects height above and below
1012
1034
// the input.
1013
1035
float prefixHeight = this . prefix == null ? 0 : this . prefix . size . height ;
1014
1036
float suffixHeight = this . suffix == null ? 0 : this . suffix . size . height ;
1015
1037
float fixHeight = Math . Max (
1016
- boxToBaseline [ this . prefix ] ,
1017
- boxToBaseline [ this . suffix ]
1038
+ boxToBaseline . getOrDefault ( this . prefix , 0.0f ) ,
1039
+ boxToBaseline . getOrDefault ( this . suffix , 0.0f )
1018
1040
) ;
1019
1041
float fixAboveInput = Math . Max ( 0 , fixHeight - inputInternalBaseline ) ;
1020
1042
float fixBelowBaseline = Math . Max (
1021
- prefixHeight - boxToBaseline [ this . prefix ] ,
1022
- suffixHeight - boxToBaseline [ this . suffix ]
1043
+ prefixHeight - boxToBaseline . getOrDefault ( this . prefix , 0.0f ) ,
1044
+ suffixHeight - boxToBaseline . getOrDefault ( this . suffix , 0.0f )
1023
1045
) ;
1024
1046
float fixBelowInput = Math . Max (
1025
1047
0 ,
@@ -1067,13 +1089,13 @@ _RenderDecorationLayout _layout(BoxConstraints layoutConstraints) {
1067
1089
float subtextHelperHeight = 0 ;
1068
1090
if ( this . counter != null ) {
1069
1091
subtextCounterBaseline =
1070
- containerHeight + subtextGap + boxToBaseline [ this . counter ] ;
1092
+ containerHeight + subtextGap + boxToBaseline . getOrDefault ( this . counter , 0.0f ) ;
1071
1093
subtextCounterHeight = this . counter . size . height + subtextGap ;
1072
1094
}
1073
1095
1074
1096
if ( helperErrorExists ) {
1075
1097
subtextHelperBaseline =
1076
- containerHeight + subtextGap + boxToBaseline [ this . helperError ] ;
1098
+ containerHeight + subtextGap + boxToBaseline . getOrDefault ( this . helperError , 0.0f ) ;
1077
1099
subtextHelperHeight = helperErrorHeight ;
1078
1100
}
1079
1101
0 commit comments