找到了解决方案,那就是使用三重引号。
Text(“”“Loooong文字...转到此处。”“”)
这是我在项目中所做的,目的是防止单词在行中间被打乱。
enter image description here
没有它。其中一些单词被换成了新的一行。
enter image description here
最佳答案
以下代码可能会有所帮助。关键是使用不间断的零宽度字符“\ u200d”。有关更多选项,请引用this site
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)),
])),
)
),
),
);
}
}
关于flutter - Flutter文本小部件将中间的单词分解到下一行如何停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62441961/