我想添加一个项目上的涟漪,它是正常的,直到我添加一个使用BoxDecoration的项目渐变.

Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
      child: Material(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)),
        elevation: 6.0,
        shadowColor: Colors.grey[50],
        child: InkWell(
          onTap: () {},
          child: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                begin: AlignmentDirectional.bottomStart,
                end: AlignmentDirectional.topEnd,
                colors: [
                  Colors.yellow[800],
                  Colors.yellow[700],
                ],
              ),
            ),
            padding: EdgeInsets.all(16.0),
            child: Text(
              widget.title,
              style: TextStyle(
                fontSize: 20.0,
                color: Colors.white,
              ),
            ),
          ),
        ),
      ),
    );
  }

推荐答案

我找到了解决方案:

我需要一个InkwellMaterial,一个Material的立面和圆角边框. 内部Material的类型为MaterialType.transparency,因此它不会在其父对象的框装饰上绘制任何内容,并且仍然保留墨迹效果.阴影和边框由外部Material控制.

Container(
      margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
      child: Material(  // <----------------------------- Outer Material
        shadowColor: Colors.grey[50],
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)),
        elevation: 6.0,
        child: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: AlignmentDirectional.bottomStart,
              end: AlignmentDirectional.topEnd,
              colors: [
                AppColors.pinkDark,
                AppColors.pink,
              ],
            ),
          ),
          child: Material(  // <------------------------- Inner Material
            type: MaterialType.transparency,
            elevation: 6.0,
            color: Colors.transparent,
            shadowColor: Colors.grey[50],
            child: InkWell(  //<------------------------- InkWell
              splashColor: Colors.white30,
              onTap: () {},
              child: Container(
                padding: EdgeInsets.all(16.0),
                child: Row(
                  children: <Widget>[
                    Icon(
                      Icons.work,
                      size: 40.0,
                      color: Colors.white,
                    ),
                    SizedBox(
                      width: 20.0,
                    ),
                    Column(
                      children: <Widget>[
                        Text(
                          widget.title,
                          style: TextStyle(
                            fontSize: 20.0,
                            color: Colors.white,
                          ),
                        ),
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );

Flutter相关问答推荐

如何在Flutter的easy_translation包中链接嵌套的链接翻译?

使用Flutter 提供程序包加载状态应用程序时,在自定义按钮中显示CircularProgressIndicator

MobX Build_Runner问题:不生成.G文件(Flutter )

如何在FiRestore中正确编写OR查询

如何在WidgetRef引用外部的函数中使用Riverpod刷新数据

在创建肘部并使用冻结时,无法使用中的Copy With方法

为什么Build_Runner的输出为0?

无法在我的Flutter 应用程序中使用GoRouter测试导航

如何使用flutter_local_notification包处理通知操作?

try 使用fl_Chart of Ffltter,但在导入它时遇到以下错误:Error:';TextScaler';is;t a type

Flutter :URI的目标不存在

为Android生成时出现Flutter 错误:给定资源值的<;COLOR&>无效

Flutter卡内容未在水平列表视图中居中

无法应用插件com.chaquo.python

在Flutter中为容器实现线性渐变背景动画

我想在文本结束后显示分隔线.它会在第一行、第二行或第三行结束

如何修复 ICU Lexing 错误:Flutter 中的意外字符

如何在 Flutter 中滚动时为多个小部件设置动画

如何在 Flutter 执行通知时运行后台代码?

为什么 orientation == Orientation.portrait 总是正确的,尽管我的设备已经处于横向