flutter - Flutter文本小部件将中间的单词分解到下一行如何停止
问题描述
找到了解决方案,它是使用三引号。
Text("""Loooong text ... 放在这里。""")
这就是我的项目中所做的,以防止单词在行中间被打断。 在此处输入图像描述
没有它。其中一些词在新行中被分成两半。 在此处输入图像描述
解决方案
下面的代码可能会有所帮助。关键是使用不间断的零宽度字符“\u200d”。更多选项请参考本站
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Center(
child: Container(
padding:EdgeInsets.only(left: 30, right:30),
child:RichText(
text: TextSpan(children: [
TextSpan(
text: "这是一趟十分令人",
style: TextStyle(color: Colors.green, fontSize: 30.0)),
TextSpan(
text: "愉\u200d悦",
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
fontSize: 30.0),
),
TextSpan(
text: "的旅程",
style: TextStyle(color: Colors.green, fontSize: 30.0)),
])),
)
),
),
);
}
}
推荐阅读
- c# - '强类型' 泛型集合,包含任何
给定接口/类的 - python - requests.exceptions.ConnectionError:无法建立新连接:[Errno 111] 连接被拒绝
- css - 角度内容不会滚动
- google-slides-api - 如何通过 Google Slides API 将对象形状图像蒙版应用于图像
- c# - xUnit,Moq - 测试 .Net Core 存储库
- javascript - Firebase 存储下载到用户计算机
- youtube-api - Google API(youtube 搜索)总是按相关性而不是日期对结果进行排序
- android - 未调用 RecyclerView 标头的 OnClickListener
- ocaml - 创建一个可以更新的大小为 x 的空字符串数组
- ios - CollectionViewCell 绘制矩形