【问题标题】:Is there any way to set elevation color in the RaisedButton widget?有没有办法在 RaisedButton 小部件中设置高度颜色?
【发布时间】:2021-05-23 22:44:41
【问题描述】:

这是一个例子:

RaisedButton(
 shape: RoundedRectangleBorder(
  borderRadius: BorderRadius.circular(10),
 ),
 padding: EdgeInsets.zero,
 elevation: 5, //Here is the elevation size
 onPressed: onPressed,
),

我想它应该适用于这个包装ElevatedButtonThemeData,但它不起作用

MaterialApp(
  title: 'Demo',
  theme: ThemeData(
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ButtonStyle(
        shadowColor: MaterialStateProperty.all<Color>(
          Colors.red, //Here
        ),
      ),
    ),
  ),

如何解决?

【问题讨论】:

标签: flutter


【解决方案1】:

您应该使用ElevatedButton 而不是RaisedButton

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      home: HomePage(),
    ),
  );
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {},
          style: ButtonStyle(
            elevation: MaterialStateProperty.all<double>(5),
            shadowColor: MaterialStateProperty.all<Color>(Colors.pink),
          ),
          child: Text('CLICK ME'),
        ),
      ),
    );
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 2018-08-22
    • 2021-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多