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不';行不通_Flutter_Dart - Fatal编程技术网

Flutter 用于将文本适配到容器的FittedBox不';行不通

Flutter 用于将文本适配到容器的FittedBox不';行不通,flutter,dart,Flutter,Dart,我试图用FittedBox将文本适配到容器中,但它不起作用。在设备上,文本向右移动,并且不会中断到下一行。(在设备上,我有权发出溢出警告)。 有人知道这个代码有什么问题吗?我认为行和列的组合存在一些问题,所以FittedBox不会影响文本,但我不确定。 谢谢 首先FittedBox不会将文本拆分为新行,它只是减少或增加文本上的字体大小。其次,您现在为FittedBox提供了任何约束,用一个容器包装它并设置它的宽度。只需使用Flexible小部件将其设置为列的父项 Flexible(

我试图用FittedBox将文本适配到容器中,但它不起作用。在设备上,文本向右移动,并且不会中断到下一行。(在设备上,我有权发出溢出警告)。 有人知道这个代码有什么问题吗?我认为行和列的组合存在一些问题,所以FittedBox不会影响文本,但我不确定。 谢谢


首先FittedBox不会将文本拆分为新行,它只是减少或增加文本上的字体大小。其次,您现在为FittedBox提供了任何约束,用一个容器包装它并设置它的宽度。

只需使用
Flexible
小部件将其设置为
列的父项

  Flexible( 
          child: Column(
           //...
         ));
          
完整示例:

Container(
      decoration: BoxDecoration(
          color: color, borderRadius: BorderRadius.all(Radius.circular(10))),
      height: MediaQuery.of(context).size.height * 0.40,
      width: MediaQuery.of(context).size.width * 0.85,
      child: Padding(
        padding: new EdgeInsets.all(20),
        child: Row(
          //mainAxisAlignment: MainAxisAlignment.start, --> NOT NECESSARY
          children: [
            Flexible(
              child: Column(
                //mainAxisAlignment: MainAxisAlignment.start, --> NOT NECESSARY
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    'hi',
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 20,
                        fontWeight: FontWeight.bold),
                  ),
                  SizedBox(height: 10),
                  FittedBox(
                      fit: BoxFit.contain,
                      child: Text(
                        'kodsajhnidoasdoisahioasdohiasdhioúsadiophas',
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 15,
                            fontWeight: FontWeight.normal),
                      )),
                ],
              ),
            )
          ],
        ),
      ),
    );

小部件导致问题,因为它在水平方向上占据了全部空间,通过添加灵活的控件,它可以根据文本进行收缩/增长。

那么我应该使用什么呢?@RitchyCZE
容器(宽度:50,child:FittedBox(child:text('adhshefjneffief'),)
@RitchyCZE和这个
容器(宽度:50,child:FittedBox(child:text('ADHSHEFJNEFFIEF',maxLines:2,overflow:TextOverflow.visible,),),)
检查文本属性。@RitchyCZE:看看上面的答案,它应该适合你。
Container(
      decoration: BoxDecoration(
          color: color, borderRadius: BorderRadius.all(Radius.circular(10))),
      height: MediaQuery.of(context).size.height * 0.40,
      width: MediaQuery.of(context).size.width * 0.85,
      child: Padding(
        padding: new EdgeInsets.all(20),
        child: Row(
          //mainAxisAlignment: MainAxisAlignment.start, --> NOT NECESSARY
          children: [
            Flexible(
              child: Column(
                //mainAxisAlignment: MainAxisAlignment.start, --> NOT NECESSARY
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    'hi',
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 20,
                        fontWeight: FontWeight.bold),
                  ),
                  SizedBox(height: 10),
                  FittedBox(
                      fit: BoxFit.contain,
                      child: Text(
                        'kodsajhnidoasdoisahioasdohiasdhioúsadiophas',
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 15,
                            fontWeight: FontWeight.normal),
                      )),
                ],
              ),
            )
          ],
        ),
      ),
    );