flutter - How to make a raised button that has a gradient background?

后端 未结 10 1691
野性不改
野性不改 2021-01-31 14:52

Is there a way to change the raised button background color to a gradient? if not, how can I achieve something like this?

10条回答
  •  终归单人心
    2021-01-31 15:38

    You can use a more easier way by using RawMaterialButton from material.dart , you can make it's shape as rounded or circle too . here is a simple example of this .

      Card(
        elevation: 7,
        child: Container(
          width: 120.0,
          height: 75.0,
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.bottomLeft,
              end: Alignment.topRight,
              colors: [
                Colors.blue,
                Colors.red,
              ],
            ),
          ),
          child: RawMaterialButton(
            onPressed: () {},
            splashColor: Colors.grey,
            child: Text(
              "Button",
              style: TextStyle(color: Colors.white, fontSize: 20.0),
            ),
          ),
        ),
      ),
    

提交回复
热议问题