为 Flutter RaisedButton 设置样式的正确方法是什么?

时间:2021-01-14 06:25:35

标签: flutter

目前我正在使用

MaterialApp(
    theme: ThemeData(
    buttonTheme: ButtonThemeData(
       buttonColor: Colors.blueAccent,
       shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20) ),
       textTheme: ButtonTextTheme.primary
    )
  )
)

但是假设只有一种样式适用于整个应用程序中的所有按钮是很疯狂的。

目前我有 4 种类型的样式可以应用于 RaisedButton,但想不出一个好的方法。为每种样式子类化 RaisedButton 也有点麻烦。

1 个答案:

答案 0 :(得分:0)

您可以访问 RaisedButton 的参数

 RaisedButton(
            onPressed: () {},
            textColor: Colors.white,
            padding: const EdgeInsets.all(0.0),
            child: Container(
              decoration: const BoxDecoration(
                gradient: LinearGradient(
                  colors: <Color>[
                    Color(0xFF0D47A1),
                    Color(0xFF1976D2),
                    Color(0xFF42A5F5),
                  ],
                ),
              ),
              padding: const EdgeInsets.all(10.0),
              child:
                  const Text('Gradient Button', style: TextStyle(fontSize: 20)),
            ),
          ),