0

I try to build a custom layout that is a Card() with 2 properties : Widget title, and Widget content.

I would like to apply a default text style on the title widget, if it is a Text widget, ie. like flutter does in AppBar. It is easy if the title widget is always a Text() widget, but I can't find how to deal with it if it can be any other widget...

What I want to do is :

// This one should work and apply a default text style on the title widget
@override
Widget build(BuildContext context)
{
    return MyCard(
        title: Text("foo"),
        content: Text("bar")
    );
}

// this one should work too
@override
Widget build(BuildContext context)
{
    return MyCard(
        title: Icon(Icons.star),
        content: Text("bar")
    );
}

// and this one should style the text with the default style +++
@override
Widget build(BuildContext context)
{
    return MyCard(
        title: Row(children: [ Text("part of "), Text("the title") ]),
        content: Text("bar")
    );
}

ThemeData and Theme(data: xxx, child: Card(.....)) let me define the entire theme, but it does not specify how to apply the right textTheme to the title widget.

How to do this ?

EDIT : added the 3rd example to make it easier to understand.

Galactose
  • 175
  • 3
  • 8

1 Answers1

0

You can provide a textTheme property in your Material widget in the main.dart file.

enter image description here

  • This is to define the entire app's textTheme and use different styles across the app. I want to create a custom layout that can receive a Text as a child, and so apply a specific style on it. Also, if the child is a Row() containing multiple Text() widgets, I would like them to be all styled the same way. I edited to make it more simple to understand what I want. – Galactose May 22 '22 at 20:03