Is it possible to use a gradient on a TextField in flutter?

Viewed 463

i'm tryng to use a gradient on a textfield border but without sucess. is it possible?

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

it says "The argument type 'LinearGradient' can't be assigned to the parameter type 'Color'"

2 Answers

You have to use Container for LinearGradient,

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
          ),
        ),
      ),
    ),
  );
Related