【问题标题】:In Flutter, is it possible to set my MaterialApp's themeData to use uppercase as default for all Text Values?在 Flutter 中,是否可以将我的 MaterialApp 的 themeData 设置为使用大写作为所有文本值的默认值?
【发布时间】:2020-06-04 04:39:31
【问题描述】:

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

...
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(),
    );
...

不幸的是,我不知道如何做到这一点,另一种有效的方法将被接受。谢谢。 一个大部分使用大写字母的应用程序示例

【问题讨论】:

    标签: flutter text dart themes textstyle


    【解决方案1】:

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

    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 小部件的地方使用它。

    【讨论】:

      猜你喜欢
      • 2014-06-13
      • 2019-08-24
      • 2014-10-15
      • 2021-07-22
      • 2021-08-26
      • 2020-09-01
      • 2016-12-28
      • 2019-08-17
      • 1970-01-01
      相关资源
      最近更新 更多