How to dynamically resize text in Flutter?

后端 未结 7 1682
梦如初夏
梦如初夏 2021-01-31 06:53

I retrieve a piece of text from an API. I want to allot a set amount of space to it (say a max Container with width: 300.0 and height: 100.0). Sometimes, the piece of text fits

7条回答
  •  旧时难觅i
    2021-01-31 07:42

    You can use FittedBox to manage text based on height or width.

    For Ex.

    Simply just wrap your Text widget to FittedBox widget like, Here I want to resize my AppBar text based on width.

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

    Text will be resized based on width of AppBar.

提交回复
热议问题