Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter apply or copyWith method

Tags:

flutter

I'm trying to apply blue color on Theme.of(context).textTheme.headline6, it can be done in two ways

Text(
  "Hello",
  style: Theme.of(context)
      .textTheme
      .headline6!
      .copyWith(color: Colors.blue),
),

or

Text(
  "Hello",
  style: Theme.of(context)
      .textTheme
      .headline6!
      .apply(color: Colors.blue),
),

Which one you prefer copyWith or apply method?

Preview on image

like image 542
Abu Anwar Avatar asked Apr 10 '26 01:04

Abu Anwar


1 Answers

The main difference is that apply() offers several parameters to scale parameters of the source TextStyle.

For example, copyWith(fontSize: 14) lets you explicitly set the font size, while apply(fontSizeFactor: 1.6) lets you scale the source's font size by a custom factor (note that an explicit fontSize parameter does not exist in apply()).

like image 139
David Schneider Avatar answered Apr 11 '26 21:04

David Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!