Murat Aslan
Murat Aslan

Reputation: 1580

How to change the `TextFormField`'s `textScaleFactor` value?

How to change TextFormField's textScaleFactor like on text widget below?

Text(
  '...',
  textScaleFactor: 1,
),

Upvotes: 1

Views: 1833

Answers (1)

Murat Aslan
Murat Aslan

Reputation: 1580

I have found the way :)

1. A Simple Solution

final double scaleFactor = MediaQuery.of(context).textScaleFactor;

TextFormField(
  style: TextStyle(
    fontSize: 16 / scaleFactor,
  ),
),

There is also a sort of shortcut for this: MediaQuery.textScaleFactorOf(context).

2. An Alternative (Better?)

You could also do something like changing the MediaQuery subcontext for the widget itself:

MediaQuery(
  data: MediaQuery.of(context).copyWith(
    textScaleFactor: 2 * MediaQuery.textScaleFactorOf(context),
  ),
  child: TextFormField(...),
),

Upvotes: 3

Related Questions