Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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 如何包装RichText小部件,然后,如果RichText小部件对于扩展的小部件来说太大,如何将其缩小?_Flutter - Fatal编程技术网

Flutter 如何包装RichText小部件,然后,如果RichText小部件对于扩展的小部件来说太大,如何将其缩小?

Flutter 如何包装RichText小部件,然后,如果RichText小部件对于扩展的小部件来说太大,如何将其缩小?,flutter,Flutter,我在一列中有两个扩展的小部件。第一个扩展的小部件包含一个RichText小部件,其中包含可变长度的文本。如果文本溢出,它将被切断。我想要实现的是,如果内容太大,整个RichText小部件将缩小。我曾经尝试过FittedBox,它通常适用于文本小部件,但当我将其应用于RichText小部件时,小部件会缩小,但包装会被删除。如果richtext小部件太大,无法扩展,那么如何包装并缩小 return Container( child: Column(children: [ Expanded

我在一列中有两个扩展的小部件。第一个扩展的小部件包含一个RichText小部件,其中包含可变长度的文本。如果文本溢出,它将被切断。我想要实现的是,如果内容太大,整个RichText小部件将缩小。我曾经尝试过FittedBox,它通常适用于文本小部件,但当我将其应用于RichText小部件时,小部件会缩小,但包装会被删除。如果richtext小部件太大,无法扩展,那么如何包装并缩小

return Container(
    child: Column(children: [
  Expanded(
      flex: 1,
      // child:FittedBox(fit: BoxFit.scaleDown,
      child: RichText(
        text: TextSpan(
            text:
                "I am a TextSpan widget and am veyr very long lskjdf lskdj flksj dflksjd lfkj",
            style:
                DefaultTextStyle.of(context).style.copyWith(fontSize: 35)),
      )),
  Expanded(flex: 4, child: Text("blah blah"))
]));


[更新

Container(
  child: Column(
    children: [
      Expanded(
        flex: 1,
        // child:FittedBox(fit: BoxFit.scaleDown,
        child: AutoSizeText.rich(
          TextSpan(text: "A really long String"),
          style: DefaultTextStyle.of(context).style.copyWith(fontSize: 35),
        )
      ),
      Expanded(
        flex: 4,
        child: Text("blah blah")
      )
    ]
  )
)

[已更新]

Container(
  child: Column(
    children: [
      Expanded(
        flex: 1,
        // child:FittedBox(fit: BoxFit.scaleDown,
        child: AutoSizeText.rich(
          TextSpan(text: "A really long String"),
          style: DefaultTextStyle.of(context).style.copyWith(fontSize: 35),
        )
      ),
      Expanded(
        flex: 4,
        child: Text("blah blah")
      )
    ]
  )
)

您是否尝试过遵循此库的逻辑:?您是否尝试过遵循此库的逻辑:?已在评论和链接库中解决,没有任何示例或解释其工作原理,这不是答案。在我发布之前,我确实尝试过这个软件包,但是如果不设置最大行数,我就无法让它工作。非常感谢您的努力,但是您的示例不显示富文本,并且它有一个高度和宽度(我需要在一个可扩展的小部件中)@orangesherbert我意识到
AutoSizeText
也适用于
RichText
,我的答案中没有包括这方面的内容。它也可以在不设置最大行数的情况下工作,也不必将其放入具有高度和长度的
容器中width@orangesherbert检查更新的答案。我希望这对你来说很好。已经在评论和链接库中讨论过了,没有任何例子或解释它是如何工作的,这不是答案。在我发布之前,我确实尝试过这个软件包,但是如果不设置最大行数,我就无法让它工作。非常感谢您的努力,但是您的示例不显示富文本,并且它有一个高度和宽度(我需要在一个可扩展的小部件中)@orangesherbert我意识到
AutoSizeText
也适用于
RichText
,我的答案中没有包括这方面的内容。它也可以在不设置最大行数的情况下工作,也不必将其放入具有高度和长度的
容器中width@orangesherbert检查更新的答案。我希望这对你有用。