首页 > 解决方案 > 如何在定位的孩子中换行?

问题描述

我正在尝试显示一个图像,它旁边会有一个文本,但我的文本太长了,无法适应屏幕。这是我的代码:

Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.blueGrey,
      appBar: new AppBar(
        backgroundColor: Colors.grey,
        title: new Align(
          alignment: Alignment.center,
          child: Text("Demo"),
        ),
      ),
      body: Stack(
        children: [
          Positioned(
            top: 50,
            left: 25,
            child: Image(
              image: NetworkImage(
                  "https://reimg-teknosa-cloud-prod.mncdn.com/mnresize/200/200/productimage/125036758/125036758_0_MC/48543732.jpg"),
              height: 300,
              width: 200,
              fit: BoxFit.fitWidth,
            ),
          ),
          Container(
            child: Positioned(
              top: 70,
              left: 260,
              child: Text(
                "Durum: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaB",
                style: GoogleFonts.sourceSerifPro(
                  fontSize: 20,
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}

我尝试了溢出:TextOverflow.clip,没有工作,我搜索了灵活和扩展,但我无法将它们放在我的代码中。我试图放置它们而不是 Container 但这不起作用。如果不合适,我怎样才能让我的文本继续下线?提前致谢。

标签: flutterdart

解决方案


像这样更改您的代码:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.blueGrey,
      appBar: new AppBar(
        backgroundColor: Colors.grey,
        title: new Align(
          alignment: Alignment.center,
          child: Text("Demo"),
        ),
      ),
      body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(20),
              child: Center(
                child: Text(
                  "Durum: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaB",
                  style: GoogleFonts.sourceSerifPro(
                    fontSize: 20,
                  ),
                ),
              ),
            ),
            Image(
              image: NetworkImage(
                  "https://reimg-teknosa-cloud-prod.mncdn.com/mnresize/200/200/productimage/125036758/125036758_0_MC/48543732.jpg"),
              height: 300,
              width: 200,
              fit: BoxFit.fitWidth,
            ),
          ],
        ),
    );
  }
}

推荐阅读