In the general ThemeData
of my flutter app, I have the following code to give a general style to the NavigationBar
.
This is the way to style the label under the icon within NavigationBarTheme
, based on the doc.
In the class that handles the Navigation
, so elsewhere in the app, I need to add color
property to the TextStyle
, maintaining the other properties via Theme.of(context)
.
But how can I do this with WidgetStateProperty.all
?
Thanks in advance!
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
navigationBarTheme: NavigationBarThemeData(
labelTextStyle: WidgetStateProperty.all(
const TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w700,
letterSpacing: 1.0,
),
),
),
),
);
}
2
Answers
Do you mean doing something like this??
You can resolve the
WidgetStateProperty
for all the possible states (since you’re applying the same style to every states anyway) to get the underlyingTextStyle
and usecopyWith
on that resolved value.You can also make extension methods to help with these tasks: