Home > Software engineering >  What is the equivalent of textScaleX and autoSizeTextType in Flutter
What is the equivalent of textScaleX and autoSizeTextType in Flutter

Time:11-25

In Android, I used textScaleX to stretch the font. I also used autoSizeTextType to make the font's size responsive. Any idea how to do that in Flutter?

    <Button
    android:id="@ id/buttonMinus"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:text="-"
    android:textScaleX="1.8"
    app:autoSizeTextType="uniform"
    app:autoSizeMaxTextSize="36sp" />

CodePudding user response:

There are lots of packages you can use to make texts responsive to all phones such as:

https://github.com/layounisl/responsive_flutter

https://pub.dev/packages/auto_size_text

But in my opinion, the best option is to use FittedBox widget. Simply just wrap your Text widget to FittedBox widget. Like I am using fittedBox in the below code to resize to the width of appbar.

AppBar(
    centerTitle: true,
    title: FittedBox(
        fit: BoxFit.fitWidth, 
        child: Text('Hey this is my long text appbar title')
    ),
),

This will always keep your text inside the box. Play around with the fit parameter and you'll see how it works.

  • Related