Shariar Saimon
Shariar Saimon

Reputation: 943

How to fix the position of the text by resizing the font size according to the device screen size in flutter app?

I have used a BottomAppBar widget and a floatingActionButton, In the picture some letters goes down which doesn't look nice.so instead is there a way to make those font size vary automatically depending on the screen size and remain in the same row?enter image description here

Upvotes: 0

Views: 232

Answers (2)

Cyrus the Great
Cyrus the Great

Reputation: 5922

Simply just wrap your Text widget to FittedBox widget like,

AppBar(
   centerTitle: true,
   title: FittedBox(fit:BoxFit.fitWidth, 
   child: Text('This is fitted box test')
  ),
),

Or you can use this lib https://pub.dev/packages/auto_size_text

Upvotes: 1

Sachin Mamoru
Sachin Mamoru

Reputation: 486

Use one of the following methods!

Use flutter AutoSizeText widget

https://pub.dev/packages/auto_size_text

AutoSizeText(
      "yourText",
      style: TextStyle(fontSize: 30.0),
),

You can use flutter FittedBox also:

https://api.flutter.dev/flutter/widgets/FittedBox-class.html

AppBar(
    centerTitle: true,
    title: FittedBox(fit:BoxFit.fitWidth, 
    child: Text('Text which need to be resized')
           ),
),

Upvotes: 1

Related Questions