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

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

    The Flutter API doc has an example of how to render a RaisedButton with gradient background - see here https://api.flutter.dev/flutter/material/RaisedButton-class.html

    Widget gradientButton = Container(
      child: RaisedButton(
        onPressed: () { },
        textColor: Colors.white,
        padding: const EdgeInsets.all(0.0),
        child: Container(
          width: 300,
          decoration: new BoxDecoration(
            gradient: new LinearGradient(
              colors: [
                Color.fromARGB(255, 148, 231, 225),
                Color.fromARGB(255, 62, 182, 226)
              ],
            )
          ),
          padding: const EdgeInsets.all(10.0),
          child: Text(
            "Gradient Button",
            textAlign: TextAlign.center,
          ),
        ),
      ),
    );
    

提交回复
热议问题