Reputation: 247
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.
Upvotes: 0
Views: 1212
Reputation: 369
You can provide a textTheme property in your Material widget in the main.dart file.
Upvotes: 0