I implemented the ability to dynamically switch between darkTheme
and lightTheme
in a Flutter app using Riverpod. However, I am unable to make the keyboard color responsive
. I want to reflect the user's choice of darkTheme
or lightTheme
when they leave the app, switch the setting, and then return to the app. However, I'm having difficulty updating the keyboard color specifically; other widgets are responsive to the theme changes.
keyboard:
TextFormField(
keyboardType: TextInputType.emailAddress,
keyboardAppearance: ref.watch(themeModeProvider).themeMode.toBrightness,
),
ThemeModeEx:
extension ThemeModeEx on ThemeMode {
Brightness get toBrightness =>
this == ThemeMode.dark ? Brightness.dark : Brightness.light;
}
When debugging and checking what is set in the keyboardAppearance
property, I can confirm that the device's current theme is being responsively configured. However, the color of the keyboard does not change. The keyboard color is only updated after closing and reopening the keyboard.
How can I change the keyboard color in accordance with the theme when the user returns to the Flutter app without reopening the keyboard?