我正在开发一个在所有屏幕上都使用大写文本的应用程序,我认为如果我可以添加这样的东西,它是生产有效的:
...
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(),
);
...
不幸的是,我不知道如何以这种方式做到这一点,另一种有效的方法将被接受。谢谢。
一个主要使用大写的应用示例
最佳答案
我认为不可能在主题中设置它,但是您可以做的是创建这个自定义小部件:
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/