容器内的颤动文本,RenderFlex 被右侧的像素溢出

问题描述 投票:0回答:1

嘿,我想不出一种方法来修复容器内的文本,它会破坏线条并自行扩展容器。我已经寻找解决方案,但扩展和灵活不起作用。有人可以帮助我吗? :)

这是问题的图片:

enter image description here

myContainer({required String title}) {
 return Padding(
  padding: const EdgeInsets.only(bottom: 5.0),
  child: SizedBox(
      child: Padding(
    padding: const EdgeInsets.only(top: 8.0),
    child: GestureDetector(
      onTap: () {
        print("Das hat funktioniert");
      },
      child: Container(
          decoration: BoxDecoration(
            color: const Color.fromRGBO(86, 89, 94, 1),
            borderRadius: BorderRadius.circular(15.0),
            border: Border.all(
              color: Color.fromRGBO(255, 128, 0, 1),
              width: 2,
            ),
          ),
          padding: EdgeInsets.only(top: 10, bottom: 10),
          child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(children: [
                  Padding(
                    padding: const EdgeInsets.only(
                        left: 12.0, top: 14, bottom: 14),
                    child: Container(
                      child: Text(
                        title,
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 22,
                            fontWeight: FontWeight.w400),
                      ),
                    ),
                  ),
                ])
              ])),
    ),
  )));

非常感谢!

flutter text overflow flutter-renderflex-error
1个回答
0
投票

将您的文本小部件添加到 Expandable 中:

Padding(
      padding: const EdgeInsets.only(bottom: 5.0),
      child: SizedBox(
        child: Padding(
          padding: const EdgeInsets.only(top: 8.0),
          child: GestureDetector(
            onTap: () {
              print("Das hat funktioniert");
            },
            child: Container(
              decoration: BoxDecoration(
                color: const Color.fromRGBO(86, 89, 94, 1),
                borderRadius: BorderRadius.circular(15.0),
                border: Border.all(
                  color: Color.fromRGBO(255, 128, 0, 1),
                  width: 2,
                ),
              ),
              padding: EdgeInsets.only(top: 10, bottom: 10),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    child: Row(children: [
                      Expanded(
                        child: Padding(
                          padding: const EdgeInsets.only(
                              left: 12.0, top: 14, bottom: 14),
                          child: Container(
                            child: Text(
                              'Add your long title here after Expanded it does not give any type of error',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 22,
                                  fontWeight: FontWeight.w400),
                            ),
                          ),
                        ),
                      ),
                    ]),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    ),

结果:image

© www.soinside.com 2019 - 2024. All rights reserved.