flutter - Flutter文本小部件将中间的单词分解到下一行如何停止

标签 flutter dart text format longtext

找到了解决方案,那就是使用三重引号。

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/

相关文章:

Flutter 应用程序在 Android 物理设备的任务管理器中显示黑屏

flutter - 如何使用 StreamProvider 检查 Firestore 快照流的 ConnectionState?

html - 如何使用 CSS 使链接居中

python - 使用正则表达式解析大文本文件

google-maps - 如果可以使用 flutter 打开谷歌地图应用程序

charts - 如何在 Flutter 的圆环饼图的孔内添加文本

flutter - 状态变量的空值

从已解析的网页中提取 Python 文本

flutter - 错误 : Could not resolve the package 'flutter_localizations' in 'package:flutter_localizations/flutter_localizations.dart'

dart - 在 flutter 中使用 google map 时出现错误