flutter - 在 Flutter 中,是否可以将我的 MaterialApp 的 themeData 设置为使用大写作为所有文本值的默认值?

标签 flutter text dart themes textstyle

我正在开发一个在所有屏幕上都使用大写文本的应用程序,我认为如果我可以添加这样的东西,它是生产有效的:

...
return MaterialApp(
      title: '***',
      theme: ThemeData(
        primaryColor: Color(0xFF101639),
        textTheme: Theme.of(context).textTheme.copyWith(
              body1: TextStyle(
                color: Colors.white,
                //*****{uppercase should be set here.. where it can take effects in all parts of the app}
              ),
            ),
      ),
      home: HomePage(),
    );
...

不幸的是,我不知道如何以这种方式做到这一点,另一种有效的方法将被接受。谢谢。
一个主要使用大写的应用示例
AN APPLICATION EXAMPLE THAT USES MOSTLY UPPERCASE

最佳答案

我认为不可能在主题中设置它,但是您可以做的是创建这个自定义小部件:

import 'package:flutter/material.dart';

class UpperCaseText extends Text {
  UpperCaseText(
    String data, {
    Key key,
    TextStyle style,
    StrutStyle strutStyle,
    TextAlign textAlign,
    TextDirection textDirection,
    Locale locale,
    bool softWrap,
    TextOverflow overflow,
    double textScaleFactor,
    int maxLines,
    String semanticsLabel,
    TextWidthBasis textWidthBasis,
  }) : super(
          data.toUpperCase(),
          key: key,
          style: style,
          strutStyle: strutStyle,
          textAlign: textAlign,
          textDirection: textDirection,
          locale: locale,
          softWrap: softWrap,
          overflow: overflow,
          textScaleFactor: textScaleFactor,
          maxLines: maxLines,
          semanticsLabel: semanticsLabel,
          textWidthBasis: textWidthBasis,
        );
}

并在任何需要大写文本的地方使用它,而不是 Text小部件。

关于flutter - 在 Flutter 中,是否可以将我的 MaterialApp 的 themeData 设置为使用大写作为所有文本值的默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60310032/

相关文章:

Flutter: 'package:flutter/src/cupertino/route.dart':断言失败:第 660 行 pos 12: '_backGestureController != null':不正确

database - flutter 地传递数据

Flutter 动画包 - 如何在用户返回时等待 Navigator.push() 执行某些操作

python - 如何计算 Pandas 数据帧上的非字母数字字符

python - Python 中的 Word Mover 距离

flutter - 在静态方法中传递 BuildContext 会导致 Flutter 中的内存泄漏吗?

firebase - Flutter Firestore 如何监听对一个文档的更改

bash - 文本文件乘法 bash linux

flutter - 没有 BuildContext 的设备像素比

dart - 如何等到图像)在 Dart 中加载