Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何使扑动中的卡片垂直堆叠?_List_Flutter - Fatal编程技术网

List 如何使扑动中的卡片垂直堆叠?

List 如何使扑动中的卡片垂直堆叠?,list,flutter,List,Flutter,我试图设计堆叠列表,但不能在颤振中进行负填充,所以我需要另一种方法来实现这种重叠效果 您可以使用堆栈和定位(知道卡的高度)。像这样: class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Home'), ), body

我试图设计堆叠列表,但不能在颤振中进行负填充,所以我需要另一种方法来实现这种重叠效果

您可以使用
堆栈
定位
(知道卡的高度)。像这样:

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home'),
      ),
      body: Stack(
        children: <Widget>[
          Positioned(
            bottom: 150.0,
            left: 0.0,
            right: 0.0,
            child: Card(
              margin: EdgeInsets.zero,
              elevation: 3.0,
              color: Colors.red,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(30.0)),
              ),
              child: Container(
                width: double.infinity,
                height: 200.0,
              ),
            ),
          ),
          Positioned(
            bottom: 50.0,
            left: 0.0,
            right: 0.0,
            child: Card(
              margin: EdgeInsets.zero,
              elevation: 3.0,
              color: Colors.blue,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(30.0)),
              ),
              child: Container(
                width: double.infinity,
                height: 200.0,
              ),
            ),
          ),
          Positioned(
            bottom: -50.0,
            left: 0.0,
            right: 0.0,
            child: Card(
              margin: EdgeInsets.zero,
              elevation: 3.0,
              color: Colors.orange,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(30.0)),
              ),
              child: Container(
                width: double.infinity,
                height: 200.0,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
类主页扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“主页”),
),
主体:堆栈(
儿童:[
定位(
底部:150.0,
左:0.0,
右:0.0,
孩子:卡片(
边距:EdgeInsets.zero,
标高:3.0,
颜色:颜色,红色,
形状:圆形矩形边框(
borderRadius:borderRadius.all(半径.圆形(30.0)),
),
子:容器(
宽度:double.infinity,
高度:200.0,
),
),
),
定位(
底部:50.0,
左:0.0,
右:0.0,
孩子:卡片(
边距:EdgeInsets.zero,
标高:3.0,
颜色:颜色,蓝色,
形状:圆形矩形边框(
borderRadius:borderRadius.all(半径.圆形(30.0)),
),
子:容器(
宽度:double.infinity,
高度:200.0,
),
),
),
定位(
底部:-50.0,
左:0.0,
右:0.0,
孩子:卡片(
边距:EdgeInsets.zero,
标高:3.0,
颜色:颜色。橙色,
形状:圆形矩形边框(
borderRadius:borderRadius.all(半径.圆形(30.0)),
),
子:容器(
宽度:double.infinity,
高度:200.0,
),
),
),
],
),
);
}
}
我建议制作一个单独的小部件以避免代码重复,也可以从列表中填充。我只是想告诉你背后的想法

这只是给你一个想法

List<Color> _colors = [Colors.orange, Colors.blue, Colors.green];

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: ListView.builder(
      itemCount: 10,
      itemBuilder: (context, index) {
        return Container(
          height: 100,
          alignment: Alignment.center,
          child: Text("Item ${index}"),
          decoration: BoxDecoration(
            color: _colors[index % 3],
            boxShadow: [BoxShadow(color: Colors.black, blurRadius: 10, spreadRadius: 5)],
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(40),
              topRight: Radius.circular(40),
            ),
          ),
        );
      },
    ),
  );
}
List\u colors=[colors.orange,colors.blue,colors.green];
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:ListView.builder(
物品计数:10,
itemBuilder:(上下文,索引){
返回容器(
身高:100,
对齐:对齐.center,
子项:文本(“项${index}”),
装饰:盒子装饰(
颜色:_颜色[索引%3],
boxShadow:[boxShadow(颜色:Colors.black,blurRadius:10,spreadRadius:5)],
borderRadius:仅限borderRadius(
左上:半径。圆形(40),
右上角:半径。圆形(40),
),
),
);
},
),
);
}

您尝试了什么,请显示代码请关闭堆栈溢出。你应该提供你的问题,并简单地工作。这是我第一次发布问题,我会尽量让它下一次更清楚