代码之家  ›  专栏  ›  技术社区  ›  atreeon

如何包装一个RichText小部件,然后,如果RichText小部件对于扩展的来说太大,就缩小它?

  •  0
  • atreeon  · 技术社区  · 6 年前

    我在一个专栏里有两个扩展的小部件。第一个扩展小部件包含一个包含可变长度文本的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"))
    ]));
    

    enter image description here

    enter image description here

    0 回复  |  直到 6 年前
        1
  •  0
  •   mjhansen3    6 年前

    [ ]

    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")
          )
        ]
      )
    )