I have defined a separate class for TextTheme
and defined the desired textStyle
, assigning it to the ThemeData
for both light and dark themes, as shown in the image. However, the textColor is not being applied in the dark mode.
When I use two separate TextTheme classes to define styles, it works correctly, but it requires writing more code.
I want to apply color styles to both light and dark themes using a single code source for styling. how can i do this? (i use getx)
my TextTheme:
class MyTextTheme {
static const String fontFamily = 'Vazir';
static TextTheme myTextTheme = TextTheme(
titleLarge: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w700,
color: Get.isDarkMode
? Color.fromARGB(255, 255, 242, 231)
: Color.fromARGB(255, 137, 116, 253)),
//
my Theme
static final lightTheme = ThemeData(
buttonTheme: const ButtonThemeData(
buttonColor: Colors.green,
),
primaryColor: Color.fromARGB(255, 62, 104, 167),
// elevetedButtom style
elevatedButtonTheme: MyButtonStyle.myElevetedButton,
// primery colors
colorScheme: ColorScheme.fromSwatch(
backgroundColor: Colors.white,
),
fontFamily: MyTextTheme.fontFamily,
brightness: Brightness.light,
// useMaterial3: true,
// text styles
textTheme: MyTextTheme.myTextTheme);
//!dark theme propertys
static final darkTheme = ThemeData(
//elevetedButton Style
elevatedButtonTheme: MyButtonStyle.myElevetedButton,
fontFamily: MyTextTheme.fontFamily,
colorScheme: ColorScheme.dark(),
textTheme: MyTextTheme.myTextTheme,
);
}
Change theme code: enter image description here
I have clarified that the problem is with the textColor
, not the textStyle as a whole.
I have clarified that using two separate TextTheme
classes is a workaround, but it is not ideal.