gpt4 book ai didi

android - 在 Flutter 中合并/合并两个 InputDecoration 实例

转载 作者:行者123 更新时间:2023-12-04 23:59:17 38 4
gpt4 key购买 nike

我在 flutter 中有两个 InputDecoration 实例,如下所示:

    final firstStyle = InputDecoration(labelText: "hello", contentPadding: EdgeInsets.all(10));
final secondStyle = InputDecoration(fillColor: Colors.lightBlue);
我现在想要的是这两个实例的组合形式,以便可以将单个组合或合并的装饰应用于输入字段,这意味着所有三个属性 labelText , contentPadding , fillColor将被应用。
我发现了一个叫做 .merge() 的东西对于 TextStyle但不适用于其他类,如 InputDecorationBoxDecoration .我应该怎么办?

最佳答案

用这个

import 'package:flutter/material.dart';

class MergeInputDecoration {
final InputDecoration input1;
final InputDecoration input2;

MergeInputDecoration({
required this.input1,
required this.input2,
});

InputDecoration merge() {
return input1.copyWith(
alignLabelWithHint: input2.alignLabelWithHint,
border: input2.border,
constraints: input2.constraints,
contentPadding: input2.contentPadding,
counter: input2.counter,
counterStyle: input2.counterStyle,
counterText: input2.counterText,
disabledBorder: input2.disabledBorder,
enabled: input2.enabled,
enabledBorder: input2.enabledBorder,
errorBorder: input2.errorBorder,
errorMaxLines: input2.errorMaxLines,
errorStyle: input2.errorStyle,
errorText: input2.errorText,
fillColor: input2.fillColor,
filled: input2.filled,
floatingLabelBehavior: input2.floatingLabelBehavior,
floatingLabelStyle: input2.floatingLabelStyle,
focusColor: input2.focusColor,
focusedBorder: input2.focusedBorder,
focusedErrorBorder: input2.focusedErrorBorder,
helperMaxLines: input2.helperMaxLines,
helperStyle: input2.helperStyle,
helperText: input2.helperText,
hintMaxLines: input2.hintMaxLines,
hintStyle: input2.hintStyle,
hintText: input2.hintText,
hintTextDirection: input2.hintTextDirection,
hoverColor: input2.hoverColor,
icon: input2.icon,
iconColor: input2.iconColor,
isCollapsed: input2.isCollapsed,
isDense: input2.isDense,
label: input2.label,
labelStyle: input2.labelStyle,
labelText: input2.labelText,
prefix: input2.prefix,
prefixIcon: input2.prefixIcon,
prefixIconColor: input2.prefixIconColor,
prefixIconConstraints: input2.prefixIconConstraints,
prefixStyle: input2.prefixStyle,
prefixText: input2.prefixText,
semanticCounterText: input2.semanticCounterText,
suffix: input2.suffix,
suffixIcon: input2.suffixIcon,
suffixIconColor: input2.suffixIconColor,
suffixIconConstraints: input2.suffixIconConstraints,
suffixStyle: input2.suffixStyle,
suffixText: input2.suffixText,
);
}
}

关于android - 在 Flutter 中合并/合并两个 InputDecoration 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67559065/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com