Detect if iOS13 Dark Mode is enabled from Flutter/Dart
Yes it is possible. Look here https://github.com/flutter/flutter/issues/33873#issuecomment-536309491 and here is the answer.
if(ios13==true){
bool qDarkmodeEnable;
var qdarkMode = MediaQuery.of(context).platformBrightness;
if (qdarkMode == Brightness.dark){
qDarkmodeEnable=true;
} else {
qDarkmodeEnable=false;
}
}
Here's how you can set different colors for light and dark mode, the app will automatically switch if the phone is set to dark mode or light mode.
MaterialApp(
theme: ThemeData(
brightness: Brightness.light,
primaryColor: Colors.red,
),
darkTheme: ThemeData(
brightness: Brightness.dark,
// additional settings go here
),
);
::Update::
You can also get the platform brightness (Brightness.light / Brightness.dark) using
WidgetsBinding.instance.window.platformBrightness
but you will have to use the WidgetsBindingObserver
mixin and override the method below
@override
void didChangePlatformBrightness() {
print(WidgetsBinding.instance.window.platformBrightness); // should print Brightness.light / Brightness.dark when you switch
super.didChangePlatformBrightness(); // make sure you call this
}
see https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver-class.html on how to use the mixin.