【问题标题】:Is it possible to use a gradient on a TextField in flutter?是否可以在颤动的 TextField 上使用渐变?
【发布时间】:2021-12-07 16:03:50
【问题描述】:

我正在尝试在文本字段边框上使用渐变,但没有成功。有可能吗?

    Widget _passwordTF() {
  return TextField(
    obscureText: true,
    decoration: InputDecoration(
      enabledBorder: OutlineInputBorder(
        borderSide: BorderSide(
          color: LinearGradient(colors: [color1, color2]),
        ),
      ),
    ),
  );
}

它说“参数类型'LinearGradient'不能分配给参数类型'Color'”

【问题讨论】:

标签: flutter dart flutter-layout


【解决方案1】:

LinearGradient 必须使用 Container,

return Container(
      decoration: BoxDecoration(
      gradient: LinearGradient(
        begin: Alignment.topRight,
        end: Alignment.bottomLeft,
        stops: [0.1, 0.5, 0.7, 0.9],
        colors: [color1, color2]
      ),
    ),
    child: TextField(
      obscureText: true,
      decoration: InputDecoration(
        enabledBorder: OutlineInputBorder(
          borderSide: BorderSide(
            color: Colors.black
          ),
        ),
      ),
    ),
  );

【讨论】:

    猜你喜欢
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多