lordvidex
lordvidex

Reputation: 4098

In Flutter, is it possible to set my MaterialApp's themeData to use uppercase as default for all Text Values?

I am working on an app that uses Uppercase texts in all screens, I think it is production effective if I can add something like this:

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

Unfortunately, I don't know how to do this in this way, another effective method will be accepted. Thanks. AN APPLICATION EXAMPLE THAT USES MOSTLY UPPERCASE AN APPLICATION EXAMPLE THAT USES MOSTLY UPPERCASE

Upvotes: 4

Views: 1185

Answers (1)

anon
anon

Reputation:

I don't think it's possible to set that in the theme, but what you can do is create this custom widget:

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,
        );
}

And use it everywhere you want upper case text instead of the Text widget.

Upvotes: 5

Related Questions