whenTheme<T> method
T
whenTheme<T>({
- required T light(),
- T dark()?,
When the theme is in light
mode, return light
function, else return dark
function
Implementation
// ignore: avoid_shadowing_type_parameters
T whenTheme<T>({
required T Function() light,
T Function()? dark,
}) {
bool isDarkModeEnabled = false;
ThemeController themeController = ThemeProvider.controllerOf(context);
if (themeController.currentThemeId == getEnv('DARK_THEME_ID')) {
isDarkModeEnabled = true;
}
if ((themeController.theme.options as NyThemeOptions).meta is Map &&
(themeController.theme.options as NyThemeOptions).meta['type'] ==
NyThemeType.dark) {
isDarkModeEnabled = true;
}
if (context.isDeviceInDarkMode) {
isDarkModeEnabled = true;
}
if (isDarkModeEnabled) {
if (dark != null) {
return dark();
}
}
return light();
}