flutter - 如何在定位的孩子中换行?
问题描述
我正在尝试显示一个图像,它旁边会有一个文本,但我的文本太长了,无法适应屏幕。这是我的代码:
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 但这不起作用。如果不合适,我怎样才能让我的文本继续下线?提前致谢。
解决方案
像这样更改您的代码:
@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,
),
],
),
);
}
}
推荐阅读
- c# - 如何在C#中缩放GraphicsPath对象上的矩形或形状时修复图片框刷新时鼠标滚轮上下之间的延迟?
- node.js - 定期重启node express server
- d3.js - 如何执行 .exit() 从以前版本的 d3.js 到版本 5.9.2 的等效操作?
- arrays - 快速查找排序下拉列表
- c# - 如何在没有自己的节点的情况下使用 QBitNinja 客户端检查比特币余额?
- laravel - 由于 [Vue 警告] 在 DELETE 路由上获得 500:避免使用非原始值作为键,而是使用字符串/数字值
- oracle - 循环经过不同时间的波谷数据块
- jquery - 点击时不调用函数
- sql - SQL中的交易、发票和文档关系
- ios - 如何创建 Swift 空二维数组以供以后添加值