简体   繁体   中英

How can I change the font size differently?

for example, I want to make 'Hello world' into 'Hello (//bigger than world) world (//smaller than Hello)' and they are in a one line.

How can I do that? Can I give their fontsize differently in one Text() widget by TextStyle()?

you can use RichText widget like this:

RichText(
  text: TextSpan(
    text: 'Hello ',
    style: DefaultTextStyle.of(context).style,
    children: <TextSpan>[
      TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
      TextSpan(text: ' world!'),
    ],
  ),
)

Please check the below code as you want.

  RichText(
      text: TextSpan(
        text: 'Hello ',
        style: TextStyle(fontSize: 24),
        children: <TextSpan>[
          TextSpan(
            text: 'world!',
            style: TextStyle(fontSize: 18),
          ),
        ],
      ),
    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM