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

后端 未结 10 1916
野性不改
野性不改 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:41

    Simply make one more container as a child set the decoration of that container and make gradient color as you want

    Then after this use RaisedButton as the child of the above container same as with MaterialButton also

       child: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
                colors: [Colors.red, Colors.blue],
                begin: FractionalOffset(0.0, 0.0),
                end: FractionalOffset(0.5, 0.0),
                stops: [0.0, 1.0],
                tileMode: TileMode.clamp),
          ),
          child: RaisedButton(
            color: Colors.transparent,
            child: Text("Ask Permssion"),
            onPressed: () {
              askPermission();
            },
          )),
    

    Output:

提交回复
热议问题