4

In Flutter I am implementing "what's new" screens which will show a preview of the real screens in the app. For that I reuse the screen Widgets in the "what's new" flow. The preview will be shown in a smaller Container and not cover the whole screen.

I want to scale down the text sizes, line heights, etc. for all widgets within this Container to match the smaller bounds. Is there a way to do this without individually adding a smaller style for every Widget separately?

e.g. scale down all fontSizes by 20% for a Widget child regardless of the size set in the theme

MrJM
  • 1,214
  • 1
  • 12
  • 26
  • I usually use MediaQuery to scale down fonts depending on the screen size tho, not the child's parent, and found this may be related to your issue https://stackoverflow.com/questions/41558368/how-can-i-layout-widgets-based-on-the-size-of-the-parent – Slah Layouni Jan 27 '20 at 11:48
  • Thanks, it is a working solution but can not be applied to my case because all fonts are defined by a fixed size – MrJM Jan 27 '20 at 12:42

1 Answers1

2

I found the solution. Wrapping the child widget tree with Transform.scale(...) will scale all the Widgets down the tree according to the supplied scale factor.

Column(
  mainAxisAlignment: MainAxisAlignment.center,
  children: [
    Transform.scale(
      scale: 0.9,
      child: MyScaledWidgetTree(),
     ),
     Container(
      child: ...,
     ),
   ],
)
MrJM
  • 1,214
  • 1
  • 12
  • 26
  • How do we make the scale dynamic so that it only scales down when there is an overflow? Also, the scale-down value should just be enough to fix the overflow. ie. be as big as it can without any overflow. How do we find that value? – Rohan Kadkol May 21 '21 at 05:16