1

我正在尝试制作一个小部件以在社交媒体平台上显示用户的帖子,我想在帖子中包含某些元素,其中一个是他在创建帖子时可能附加的外部链接。我希望这些链接由圆形按钮表示(我已经通过使用ClipOval设法实现)并且我希望这些椭圆形排列成一排,与中心均匀间隔。

这是我迄今为止描述并设法实现的图像

到目前为止,我能够将它们分开的唯一方法是添加一定宽度的SizedBox(s) 。但这对于不同的帖子效率不高,链接的数量可能不同,因此椭圆的数量也可能不同。这看起来会很乱。

我已经使用堆栈覆盖了帖子图像顶部的行(我已对其应用线性渐变以使按钮可见)。

这是我的代码

class postTemplate extends StatelessWidget {
  List <String> tags = ['tag1','tag2','tag3','tag4','tag5','tag6','tag7','tag8'];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          SizedBox(height: 150,),
          Container(
            height: 450,
            child: Stack(
              children: <Widget>[
                Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    SizedBox(height: 20,),
                    Card(
                      elevation: 8.0,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(32)
                      ),
                      color: Colors.white,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          ListTile(
                            title: Padding(
                              padding: const EdgeInsets.only(left : 70.0),
                              child: Text("Username"),
                            ),
                            subtitle: Padding(
                              padding: const EdgeInsets.only(top: 10.0,left: 80.0),
                              child: Text("Hello"),
                            ),
                          ),
                          Stack(
                            children: [
                              Container(
                                child: Container(
                                  foregroundDecoration:BoxDecoration(
                                    gradient: LinearGradient(
                            colors: [Colors.white, Colors.transparent],
                            begin: Alignment.bottomCenter,
                            end: Alignment.topCenter,
                            stops: [0, 0.3],
                          ),),
                                    child: Image(image: AssetImage('assets/images/modelPostImage.png'),fit: BoxFit.contain,)),
                              ),
                              Positioned(
                                bottom: 10.0,
                                  child: Row(
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                                    children: [
                                      SizedBox(width: 15,),
                                      Container(
                                        width: 56,
                                        decoration: BoxDecoration(
                                          shape: BoxShape.circle,
                                          boxShadow: [
                                            BoxShadow(
                                              color: Colors.black,
                                              blurRadius: 2.0,
                                              spreadRadius: 1.0,
                                            )
                                          ]
                                        ),
                                        child: ClipOval(
                                          child: Material(// button color
                                            child: InkWell(
                                              splashColor: Colors.red, // inkwell color
                                              child: SizedBox(width: 56, height: 56, child:Image(
                                                image: new AssetImage("assets/Icons/browser.jpg"),
                                                width: 32,
                                                height:32,
                                                color: null,
                                                fit: BoxFit.scaleDown,
                                              ),),
                                              onTap: () {},
                                            ),
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: 15,),
                                      Container(
                                        width: 60,
                                        decoration: BoxDecoration(
                                            shape: BoxShape.circle,
                                            boxShadow: [
                                              BoxShadow(
                                                color: Colors.black,
                                                blurRadius: 2.0,
                                                spreadRadius: 1.0,
                                              )
                                            ]
                                        ),
                                        child: ClipOval(
                                          child: Material(// button color
                                            child: InkWell(
                                              splashColor: Colors.red, // inkwell color
                                              child: SizedBox(width: 56, height: 56, child:Image(
                                                image: new AssetImage("assets/Icons/browser.jpg"),
                                                width: 32,
                                                height:32,
                                                color: null,
                                                fit: BoxFit.scaleDown,
                                              ),),
                                              onTap: () {},
                                            ),
                                          ),
                                        ),
                                      ),
                                      SizedBox(width: 15,),
                                      Container(
                                        width: 60,
                                        decoration: BoxDecoration(
                                            shape: BoxShape.circle,
                                            boxShadow: [
                                              BoxShadow(
                                                color: Colors.black,
                                                blurRadius: 2.0,
                                                spreadRadius: 1.0,
                                              )
                                            ]
                                        ),
                                        child: ClipOval(
                                          child: Material(// button color
                                            child: InkWell(
                                              splashColor: Colors.red, // inkwell color
                                              child: SizedBox(width: 56, height: 56, child:Image(
                                                image: new AssetImage("assets/Icons/browser.jpg"),
                                                width: 32,
                                                height:32,
                                                color: null,
                                                fit: BoxFit.scaleDown,
                                              ),),
                                              onTap: () {},
                                            ),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                            ],
                          ),
                          Container(
                            height: 44,
                            width: 350,
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.all(Radius.circular(22))
                            ),
                            child: ListView.builder(
                              scrollDirection: Axis.horizontal,
                              itemCount: tags.length,
                              itemBuilder: (BuildContext context, int index){
                                return Container(
                                  decoration: BoxDecoration(
                                      borderRadius: BorderRadius.circular(22),
                                      border: Border.all(color: Colors.black)
                                  ),
                                  margin: EdgeInsets.only(right: 13, left: 13),
                                  child: Padding(
                                    padding: const EdgeInsets.only(
                                        top: 10.0, bottom: 5.0, right: 20, left:20
                                    ),
                                    child: Text(tags[index],
                                      style: TextStyle(
                                          color: Colors.black
                                      ),),
                                  ),
                                );
                              },
                            ),
                          ),
                        ],
                      ),
                    )
                  ],
                ),
                CircleAvatar(
                  radius: 42,
                    backgroundImage: AssetImage('assets/Icons/profileLogo.jpg')
                )
              ],
            ),
          ),
        ],
      ),
    );
  }
}

任何帮助,将不胜感激。

4

2 回答 2

0

用容器包裹并给它全宽并去除尺寸

                    Positioned(
                        bottom: 10.0,
                        child: Container(
                            width:MediaQuery.of(context).size.width,
                          child :Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              Container(
                                width: 56,
                                decoration: BoxDecoration(
                                  shape: BoxShape.circle,
                                  boxShadow: [
                                    BoxShadow(
                                      color: Colors.black,
                                      blurRadius: 2.0,
                                      spreadRadius: 1.0,
                                    )
                                  ]
                                ),
                                child: ClipOval(
                                  child: Material(// button color
                                    child: InkWell(
                                      splashColor: Colors.red, // inkwell color
                                      child: SizedBox(width: 56, height: 56, child:Image(
                                        image: new AssetImage("assets/Icons/browser.jpg"),
                                        width: 32,
                                        height:32,
                                        color: null,
                                        fit: BoxFit.scaleDown,
                                      ),),
                                      onTap: () {},
                                    ),
                                  ),
                                ),
                              ),
                              Container(
                                width: 60,
                                decoration: BoxDecoration(
                                    shape: BoxShape.circle,
                                    boxShadow: [
                                      BoxShadow(
                                        color: Colors.black,
                                        blurRadius: 2.0,
                                        spreadRadius: 1.0,
                                      )
                                    ]
                                ),
                                child: ClipOval(
                                  child: Material(// button color
                                    child: InkWell(
                                      splashColor: Colors.red, // inkwell color
                                      child: SizedBox(width: 56, height: 56, child:Image(
                                        image: new AssetImage("assets/Icons/browser.jpg"),
                                        width: 32,
                                        height:32,
                                        color: null,
                                        fit: BoxFit.scaleDown,
                                      ),),
                                      onTap: () {},
                                    ),
                                  ),
                                ),
                              ),
                              Container(
                                width: 60,
                                decoration: BoxDecoration(
                                    shape: BoxShape.circle,
                                    boxShadow: [
                                      BoxShadow(
                                        color: Colors.black,
                                        blurRadius: 2.0,
                                        spreadRadius: 1.0,
                                      )
                                    ]
                                ),
                                child: ClipOval(
                                  child: Material(// button color
                                    child: InkWell(
                                      splashColor: Colors.red, // inkwell color
                                      child: SizedBox(width: 56, height: 56, child:Image(
                                        image: new AssetImage("assets/Icons/browser.jpg"),
                                        width: 32,
                                        height:32,
                                        color: null,
                                        fit: BoxFit.scaleDown,
                                      ),),
                                      onTap: () {},
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        ),
                    ],
                  ),
于 2020-12-21T16:02:48.620 回答
0

有一个专门的小部件可以创建均匀的空间,而不是使用 SizedBox。将 SizeBox 替换为Spacer

于 2020-12-21T16:13:12.503 回答