flutter - 如何在 Text Widget Flutter 中使用换行符
问题描述
如何在 Flutter 中显示多行文本?
Text("Text1\n Text2\n Text3",maxLines: 20, style: TextStyle(fontSize: 16.0 ,fontWeight:FontWeight.bold,color: Colors.black) , )
解决方案
方法 1使用三引号
child: Container(
child : Text('''
Text1
Text2
Text3''',maxLines: 20, style: TextStyle(fontSize: 16.0 ,fontWeight:FontWeight.bold,color: Colors.black) , )
),
方法 2使用\n这里是动态字符串的示例:
var readLines = ['Test1', 'Test2', 'Test3'];
String getNewLineString() {
StringBuffer sb = new StringBuffer();
for (String line in readLines) {
sb.write(line + "\n");
}
return sb.toString();
}
child: Container(
child: Text(
getNewLineString(),
maxLines: 20,
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
color: Colors.black),
)),
方法 3使用带有 \n 的静态文本
Text('Welcome\nto\nMyWorld\nHello\nWorld\n');
有关更多信息,您应该参考此链接 https://api.dartlang.org/stable/2.5.0/dart-core/String-class.html
推荐阅读
- elasticsearch - Fluent Bit Filter 将 Unix Epoch 时间戳转换为人类可读的时间格式
- php - 自定义 PHP 狙击程序,用于向管理员发送电子邮件通知,以了解 WooCommerce 中的待处理订单状态,从而导致处理订单的电子邮件重复
- google-maps - Google Maps SDK for Unity 在特定区域不起作用
- select - 想在一个选择的情况下使用 distinct
- sql - 表只有 FK 时无法返回列表?
- google-app-engine - 如何为谷歌云应用版本添加可写权限?
- python - Django 无法调用自定义 django 命令 extwith call_command
- php - 如何在 3.2.13 版本中禁用 symfony 开发模式和分析器
- java - 如果我将数据源从 `H2` 切换到 `postgresql`,`hibernate.hbm2ddl.import_files` 属性将停止工作
- swift - 将 Alamofire 与 .publishDecodable 一起使用