如何创建具有内部阴影和渐变填充的卡片

Sha*_*hun 3 flutter

我正在尝试创建一个类似于此图像(左侧的)的 ListView:

一个很酷的菜单 UI --注意列表的每一行都有一个从右到左的渐变,而且每一行顶部的阴影从上面的行投射

但是出于对邪恶的热爱,我无法让 Flutter 为 Card 小部件绘制渐变和内部阴影(从顶部)!

在我的 Scaffold 中,我创建了一个 ListView,里面有一堆儿童用的 InkWell。这些 InkWells 中的每一个都包含一个 Card,其中有一个 Container 作为其子项。这些容器包含由一堆文本和东西组成的行。

我已经尝试了很多技巧来为卡片颜色(BG 颜色)和 BoxShadow(不幸的是,它没有仅为小部件顶部绘制的选项)的颜色渐变(从 centerLeft 到 centerRight)。但到目前为止,还没有达到我想要的效果。

body: new ListView(
            children: <Widget>[
          new InkWell(
            onTap: () => showContent("Shadows in Flutter? :/"),
            child: new Card(
              elevation: 9.0,
              margin: EdgeInsets.all(0),
              child: new Container(
                  height: 104.0,
                  child: new Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      new Container(

                        padding: EdgeInsets.only(left: 2.0, right: 5.0),
                        child: new Text("John Smith",
                            textAlign: TextAlign.center,
                            style: new TextStyle(
                                color: Color.fromARGB(255, 224, 117, 86),),
                      ),
                    ],
                  ),
                  decoration: new BoxDecoration(
                    boxShadow: [
                      new BoxShadow(
                          color: Colors.black,
                          blurRadius: 5.0,
                          offset: Offset(0, 10.0)
                      ),
                    ],
                    gradient: LinearGradient(
                      begin: Alignment.centerLeft,
                      end: Alignment.centerRight,
                      colors: [
                        const Color.fromARGB(255, 254, 225, 111),
                        const Color.fromARGB(255, 232, 206, 96)
                      ],

                      tileMode: TileMode.clamp,
                    ),
                  )),
            ),
          ),

     ----- put a couple of Inkwell's similar to above
Run Code Online (Sandbox Code Playgroud)

阴影未正确绘制,我无法使颤动从 Listview 上的上部元素绘制单个阴影

那么,有什么方法可以实现我想要的吗?

小智 5

使用foregroundDecorationaddLinearGradient这不是答案,但可以解决阴影问题

oregroundDecoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment(-1, -1),
          end: Alignment(-1, -0.8),
          colors: [Colors.black26, Colors.transparent],
        ),
      )
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明