Yan Cordeiro
Yan Cordeiro

Reputation: 31

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

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'"

Upvotes: 3

Views: 3023

Answers (2)

Sourav 12
Sourav 12

Reputation: 71

Try using this package https://pub.dev/packages/gradient_borders It will help to get gradient border

Upvotes: 0

Urvashi
Urvashi

Reputation: 156

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

Upvotes: 1

Related Questions