Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
Flutter FittedBox inside的无边界约束已扩展的容器内宽度_Flutter_Dart - Fatal编程技术网

Flutter FittedBox inside的无边界约束已扩展的容器内宽度

Flutter FittedBox inside的无边界约束已扩展的容器内宽度,flutter,dart,Flutter,Dart,我试图做到这一点: [Buy $5,99"] 为此,我使用flex将行一分为二。第一件是买的,第二件是买的$5,99的,我很明显地把它向右对齐了 然而,我不能让它工作。我尝试了FittedBox,但也尝试了其他东西。我明白了 RenderFlex children have non-zero flex but incoming width constraints are unbounded. 这是没有意义的,因为展开的文件位于定义了宽度的容器中

我试图做到这一点:

[Buy                $5,99"]
为此,我使用
flex
将行一分为二。第一件是买
,第二件是买
的$5,99的
,我很明显地把它向右对齐了

然而,我不能让它工作。我尝试了
FittedBox
,但也尝试了其他东西。我明白了

RenderFlex children have non-zero flex but incoming width constraints are unbounded.
这是没有意义的,因为展开的文件位于定义了
宽度的容器中

     Expanded(
          child: Container(
              decoration: BoxDecoration(
                color: Colors.red,
                borderRadius: BorderRadius.only(
                  bottomLeft: const Radius.circular(ROUNDNESSS),
                  bottomRight: const Radius.circular(ROUNDNESSS),
                ),
              ),
              child: FittedBox(
                  fit: BoxFit.fitWidth,
                  child: Row(
                    children: [
                      Flexible(
                          child: Text("Buy",
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 17,
                                fontWeight: FontWeight.w700,
                                fontFamily: 'Roboto',
                              )),
                          flex: 1),
                      Flexible(
                          child: Text("\$5,99",
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 17,
                                fontWeight: FontWeight.w700,
                                fontFamily: 'Roboto',
                              )),
                          flex: 1)
                    ],
                  ))),
          flex: 3)

无法展开文本小部件。容器可以扩展,因此将每个文本小部件包装在容器中是一个开始。现在,除非展开容器,否则容器不会更改其尺寸。现在,在Expanded中有一个名为flex的属性可以工作。下面是一些工作代码

class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
  return Container(
    color: Colors.cyan,
    height: MediaQuery.of(context).size.height,
    width: MediaQuery.of(context).size.width,
    child: Center(
      child: Row(
        children: [
          Expanded(
            flex: 1,
            child: Container(
              color: Colors.red,
              child: Text("\$5,99",
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 17,
                    fontWeight: FontWeight.w700,
                    fontFamily: 'Roboto',
                  )),
            ),
          ),
          Expanded(
            flex: 1,
            child: Container(
              color: Colors.blue,
              child: Text("Buy",
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 17,
                    fontWeight: FontWeight.w700,
                    fontFamily: 'Roboto',
                  )),
            ),
          )
        ],
      ),
    ),
  );
 }
}
然而,这并没有给你想要的样子。要实现您想要的间距,有一个更简单的解决方案,使用行的mainAxisAlignment属性

child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,