android - Flutter Container BoxShadow 不显示

标签 android ios dart flutter flutter-layout

这是我此刻的代码:

ClipRRect(
  borderRadius: BorderRadius.circular(11),
  child: Container(
    decoration: BoxDecoration(
      gradient: LinearGradient(
        begin: FractionalOffset.bottomLeft,
        end: FractionalOffset.topRight,
        colors: <Color>[Colors.purple, AppBaseColors.orange],
      ),
      boxShadow: [BoxShadow(color: Colors.yellow)]
    ),
    child: Material(
      child: InkWell(
        onTap: () {
          print("tapped");
        },
        child: Container(
          width: ButtonTheme.of(context).minWidth,
          height: ButtonTheme.of(context).height,
          child: Center(
            child: Text(
              "log in",
              style: TextStyle(
                  color: Colors.white, fontWeight: FontWeight.bold),
            ),
          ),
        ),
      ),
      color: Colors.transparent,
    ),
  ),
),

我尝试了什么:

  • 在第一个Container中添加boxShadow
  • 在第二个Container中添加boxShadow
  • 添加另一个带有 boxShadowContainer 作为 ClipRRect 的父级
  • Material 中添加 boxShadow 作为 shadowColor(ofc 不起作用,因为我没有任何类型的阴影)
  • 在上述所有情况下还添加了 spreadRadiusblurRadius,但没有任何改变。

知道我做错了什么吗?

最佳答案

您需要进行这些更改:

  • 删除 ClipRRect 小部件。
  • BoxDecoration 中添加 borderRadius
  • 向您的 BoxShadow 添加一个 Offset

    Container(
              decoration: BoxDecoration(
                  color: Colors.blue,
                  gradient: LinearGradient(
                    begin: FractionalOffset.bottomLeft,
                    end: FractionalOffset.topRight,
                    colors: <Color>[Colors.purple, Colors.orange],
                  ),
                  borderRadius: BorderRadius.circular(11),
                  boxShadow: [
                    BoxShadow(color: Colors.yellow, offset: Offset(5.0, 5.0))
                  ]),
              child: Material(
                borderRadius: BorderRadius.circular(11),
                clipBehavior: Clip.hardEdge,
                child: InkWell(
                  onTap: () {
                    print("tapped");
                  },
                  child: Container(
                    width: ButtonTheme.of(context).minWidth,
                    height: ButtonTheme.of(context).height,
                    child: Center(
                      child: Text(
                        "log in",
                        style: TextStyle(
                            color: Colors.white, fontWeight: FontWeight.bold),
                      ),
                    ),
                  ),
                ),
                color: Colors.transparent,
              ),
            ),
    

关于android - Flutter Container BoxShadow 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55955383/

相关文章:

java - 缺少类日期选择器

android - 如何发送带有电子邮件附件的音频和图像文件?

ios - 域@count查询问题

ios导航栏右键项目在推送新 View Controller 时移动

process - 有没有一种方法可以在Dart中扩展Web-ui构建过程,以便在构建过程完成后将我的代码复制到其他地方?

android - 如何通过代码自动更改android系统的语言环境

android - 如何增加 Glide android 中的缓存大小?

ios - 无法识别条形码中的字符串编码

flutter - 里弗波德 : Access Provider in initState method

flutter - 查看 .pub-cache 文件给出 Request textDocument/documentSymbol failed