0

Many flutter widgets forces their child to inherit their style, like:

ElevatedButton(
    child: Text("Click Me."),
    onPressed: (){},
);

this ElevatedButton() will force its Text() child to inherit a specific text color, weight and so on...

My question is how to make a widget that forces its child to inherit a style from it, and Thank you ^^.

I tried using Theme widget but it's useless.

  • "style" is a very broad concept. Could you explain more what properties of the parent widget are you trying to pass to the child widget? – JerZaw Nov 24 '22 at 00:38
  • @JerZaw like TextStyle from the parent to the child. – Ahmed Mahdy Nov 24 '22 at 00:51
  • In that case you could use an outside function that generates the TextStyle, and return the widget to both locations – JerZaw Nov 24 '22 at 01:04
  • see [DefaultTextStyle](https://api.flutter.dev/flutter/widgets/DefaultTextStyle-class.html) - the docs say: "The text style to apply to descendant Text widgets which don't have an explicit style." – pskink Nov 24 '22 at 06:05

1 Answers1

0

as pskink mentioned in the comments DefaultTextStyle worked well.