浏览代码

fix input_decoration _layout bug (c# doesn't support null key in Dictionary while dart support Map[null] = value)

/main
xingwei.zhu 5 年前
当前提交
8e8dfe23
共有 2 个文件被更改,包括 68 次插入37 次删除
  1. 9
      Runtime/foundation/basic_types.cs
  2. 96
      Runtime/material/input_decorator.cs

9
Runtime/foundation/basic_types.cs


it.TryGetValue(key, out v);
return v;
}
public static TValue getOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> it, TKey key, TValue defaultVal) {
TValue v = defaultVal;
if (key == null) {
return v;
}
it.TryGetValue(key, out v);
return v;
}
public static T first<T>(this IList<T> it) {
return it[0];

96
Runtime/material/input_decorator.cs


_RenderDecorationLayout _layout(BoxConstraints layoutConstraints) {
Dictionary<RenderBox, float> boxToBaseline = new Dictionary<RenderBox, float>();
BoxConstraints boxConstraints = layoutConstraints.loosen();
boxToBaseline[this.prefix] = this._layoutLineBox(this.prefix, boxConstraints);
boxToBaseline[this.suffix] = this._layoutLineBox(this.suffix, boxConstraints);
boxToBaseline[this.icon] = this._layoutLineBox(this.icon, boxConstraints);
boxToBaseline[this.prefixIcon] = this._layoutLineBox(this.prefixIcon, boxConstraints);
boxToBaseline[this.suffixIcon] = this._layoutLineBox(this.suffixIcon, boxConstraints);
if (this.prefix != null) {
boxToBaseline[this.prefix] = this._layoutLineBox(this.prefix, boxConstraints);
}
if (this.suffix != null) {
boxToBaseline[this.suffix] = this._layoutLineBox(this.suffix, boxConstraints);
}
if (this.icon != null) {
boxToBaseline[this.icon] = this._layoutLineBox(this.icon, boxConstraints);
}
if (this.prefixIcon != null) {
boxToBaseline[this.prefixIcon] = this._layoutLineBox(this.prefixIcon, boxConstraints);
}
if (this.suffixIcon != null) {
boxToBaseline[this.suffixIcon] = this._layoutLineBox(this.suffixIcon, boxConstraints);
}
float inputWidth = Math.Max(0.0f, this.constraints.maxWidth - (
_boxSize(this.icon).width

+ _boxSize(this.suffix).width
+ _boxSize(this.suffixIcon).width
+ this.contentPadding.right));
boxToBaseline[this.label] = this._layoutLineBox(this.label,
boxConstraints.copyWith(maxWidth: inputWidth)
);
boxToBaseline[this.hint] = this._layoutLineBox(this.hint,
boxConstraints.copyWith(minWidth: inputWidth, maxWidth: inputWidth)
);
boxToBaseline[this.counter] = this._layoutLineBox(this.counter, boxConstraints);
if (this.label != null) {
boxToBaseline[this.label] = this._layoutLineBox(this.label,
boxConstraints.copyWith(maxWidth: inputWidth)
);
}
boxToBaseline[this.helperError] = this._layoutLineBox(this.helperError,
boxConstraints.copyWith(
maxWidth: Math.Max(0.0f, boxConstraints.maxWidth
- _boxSize(this.icon).width
- _boxSize(this.counter).width
- this.contentPadding.horizontal
if (this.hint != null) {
boxToBaseline[this.hint] = this._layoutLineBox(this.hint,
boxConstraints.copyWith(minWidth: inputWidth, maxWidth: inputWidth)
);
}
if (this.counter != null) {
boxToBaseline[this.counter] = this._layoutLineBox(this.counter, boxConstraints);
}
if (this.helperError != null) {
boxToBaseline[this.helperError] = this._layoutLineBox(this.helperError,
boxConstraints.copyWith(
maxWidth: Math.Max(0.0f, boxConstraints.maxWidth
- _boxSize(this.icon).width
- _boxSize(this.counter).width
- this.contentPadding.horizontal
)
)
);
);
}
float labelHeight = this.label == null
? 0

counterHeight,
helperErrorHeight
);
boxToBaseline[this.input] = this._layoutLineBox(this.input,
boxConstraints.deflate(EdgeInsets.only(
top: this.contentPadding.top + topHeight,
bottom: this.contentPadding.bottom + bottomHeight
)).copyWith(
minWidth: inputWidth,
maxWidth: inputWidth
)
);
if (this.input != null) {
boxToBaseline[this.input] = this._layoutLineBox(this.input,
boxConstraints.deflate(EdgeInsets.only(
top: this.contentPadding.top + topHeight,
bottom: this.contentPadding.bottom + bottomHeight
)).copyWith(
minWidth: inputWidth,
maxWidth: inputWidth
)
);
}
// The field can be occupied by a hint or by the input itself
float hintHeight = this.hint == null ? 0 : this.hint.size.height;

boxToBaseline[this.input],
boxToBaseline[this.hint]
boxToBaseline.getOrDefault(this.input, 0.0f),
boxToBaseline.getOrDefault(this.hint, 0.0f)
);
// Calculate the amount that prefix/suffix affects height above and below

float fixHeight = Math.Max(
boxToBaseline[this.prefix],
boxToBaseline[this.suffix]
boxToBaseline.getOrDefault(this.prefix, 0.0f),
boxToBaseline.getOrDefault(this.suffix, 0.0f)
prefixHeight - boxToBaseline[this.prefix],
suffixHeight - boxToBaseline[this.suffix]
prefixHeight - boxToBaseline.getOrDefault(this.prefix, 0.0f),
suffixHeight - boxToBaseline.getOrDefault(this.suffix, 0.0f)
);
float fixBelowInput = Math.Max(
0,

float subtextHelperHeight = 0;
if (this.counter != null) {
subtextCounterBaseline =
containerHeight + subtextGap + boxToBaseline[this.counter];
containerHeight + subtextGap + boxToBaseline.getOrDefault(this.counter, 0.0f);
containerHeight + subtextGap + boxToBaseline[this.helperError];
containerHeight + subtextGap + boxToBaseline.getOrDefault(this.helperError, 0.0f);
subtextHelperHeight = helperErrorHeight;
}

正在加载...
取消
保存