繁体   English   中英

如何在 Flutter 中的另一个小部件下对齐小部件?

[英]How to align widget under another widget in Flutter?

我意味着代表肚里进步的部件像这样

我需要能够将名称放在气泡下,但是当我这样做时:

Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Container(
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      border: Border.all(
                        color: Colors.green,
                        width: 1.5,
                      ),
                    ),
                    height: MediaQuery.of(context).size.height / 10,
                    width: MediaQuery.of(context).size.width / 10,
                    child: Center(
                      child: Icon(
                        Icons.check,
                        color: Colors.green,
                        size: 30,
                      ),
                    ),
                  ),
                  Text("Test label"),
                ],
              ),

发生这种情况

我还尝试将条形与圆圈排成一排:

 Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Row(
                        children: [
                          Container(
                            padding: EdgeInsets.symmetric(
                              vertical:
                                  MediaQuery.of(context).size.height / 20,
                            ),
                            height:
                                1 + MediaQuery.of(context).size.height / 10,
                            width: MediaQuery.of(context).size.width / 16,
                          ),
                          Container(
                            decoration: BoxDecoration(
                              shape: BoxShape.circle,
                              border: Border.all(
                                color: mainColor,
                                width: 1.5,
                              ),
                            ),
                            height: MediaQuery.of(context).size.height / 10,
                            width: MediaQuery.of(context).size.width / 10,
                            child: Center(
                              child: Icon(
                                Icons.check,
                                color: mainColor,
                                size: 30,
                              ),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(
                              vertical:
                                  MediaQuery.of(context).size.height /20,
                            ),
                            height:
                                1 + MediaQuery.of(context).size.height / 10,
                            width: MediaQuery.of(context).size.width / 16,
                            child: Container(
                              color: grey,
                            ),
                          ),
                        ],
                      ),
                    Text("Test label"),
                    ],
                  ),

这更好,但如果文本更大,仍然会产生问题

如何在不引起线条问题的情况下对齐圆圈下方的文本?

整个widget的代码(抱歉这么长,不然不知道怎么显示):

Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    padding: EdgeInsets.symmetric(
                      vertical:
                      MediaQuery.of(context).size.height / 20,
                    ),
                    height:
                    1 + MediaQuery.of(context).size.height / 10,
                    width: MediaQuery.of(context).size.width / 16,
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          border: Border.all(
                            color: Colors.green,
                            width: 1.5,
                          ),
                        ),
                        height: MediaQuery.of(context).size.height / 10,
                        width: MediaQuery.of(context).size.width / 10,
                        child: Center(
                          child: Icon(
                            Icons.check,
                            color: Colors.green,
                            size: 30,
                          ),
                        ),
                      ),
                      Text("Test label"),
                    ],
                  ),Container(
                    padding: EdgeInsets.symmetric(
                      vertical:
                      MediaQuery.of(context).size.height / 20,
                    ),
                    height:
                    1 + MediaQuery.of(context).size.height / 10,
                    width: MediaQuery.of(context).size.width / 16,
                    child: Container(
                      color: Colors.grey,
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(
                      vertical: MediaQuery.of(context).size.height / 20,
                    ),
                    height: 1 + MediaQuery.of(context).size.height / 10,
                    width: 3 / 2 * MediaQuery.of(context).size.width / 8,
                    child: Container(
                      color: Colors.grey,
                    ),
                  ),
                  Container(
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      border: Border.all(
                        color: Colors.grey,
                        width: 1.5,
                      ),
                    ),
                    height: MediaQuery.of(context).size.height / 10,
                    width: MediaQuery.of(context).size.width / 10,
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(
                      vertical: MediaQuery.of(context).size.height / 20,
                    ),
                    height: 1 + MediaQuery.of(context).size.height / 10,
                    width: MediaQuery.of(context).size.width / 8,
                    child: Container(
                      color: Colors.grey,
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(
                      vertical: MediaQuery.of(context).size.height / 20,
                    ),
                    height: 1 + MediaQuery.of(context).size.height / 10,
                    width: MediaQuery.of(context).size.width / 8,
                    child: Container(
                      color: Colors.grey,,
                    ),
                  ),
                  Container(
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      border: Border.all(
                        color: Colors.grey,,
                        width: 1.5,
                      ),
                    ),
                    height: MediaQuery.of(context).size.height / 10,
                    width: MediaQuery.of(context).size.width / 10,
                  )
                ],
              ),

我建议的一种解决方案是尝试使用ConstrainedBoxContainer包装文本并限制最大宽度。

例如 -

ConstrainedBox(
  constraints: BoxConstraints(maxWidth: 50),
    child: Container(
      child: Text('Your Text'),
  ),
),

认为如果文本太长而无法放在一行中,则会将文本移动到下一行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM