How do I stack widgets overlapping each other in flutter

前端 未结 4 1348
予麋鹿
予麋鹿 2020-12-25 09:48

I need to stack widgets like this:

I wrote the code below. However the coins are coming one after another with some default padding. How can I get something l

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-25 10:35

    I wanted something without dependencies and without hardcoded layout. You could enhance by making overlap use a media query to overlap in terms of %.

     Widget overlapped() {
        final overlap = 10.0;
        final items = [
          CircleAvatar(child: Text('1'), backgroundColor: Colors.red),
          CircleAvatar(child: Text('2'), backgroundColor: Colors.green),
          CircleAvatar(child: Text('3'), backgroundColor: Colors.blue),
        ];
    
        List stackLayers = List.generate(items.length, (index) {
          return Padding(
            padding: EdgeInsets.fromLTRB(index.toDouble() * overlap, 0, 0, 0),
            child: items[index],
          );
        });
    
        return Stack(children: stackLayers);
      }
    

提交回复
热议问题