lor*_*dex 4 text themes dart textstyle flutter
我正在开发一个在所有屏幕中使用大写文本的应用程序,我认为如果我可以添加如下内容,那么它的生产效率会很高:
...
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(),
);
...
Run Code Online (Sandbox Code Playgroud)
小智 5
我认为不可能在主题中设置它,但您可以做的是创建这个自定义小部件:
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,
);
}
Run Code Online (Sandbox Code Playgroud)
并在您想要大写文本而不是Text小部件的任何地方使用它。