728x90
WidgetsBindingObserver의 didChangePlatformBrightness 사용하면 된다.
앱 사용 중에 시스템 디스플레이 모드(라이트, 다크) 상태를 변경하면 상태바, 네이게이션바의 색상이 변경되지 않는다.
@override
void didChangePlatformBrightness() {
bool isDark = SchedulerBinding.instance.window.platformBrightness == Brightness.dark;
if (isDark) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.black
));
} else {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white
));
}
super.didChangePlatformBrightness();
}
WidgetsBindingObserver class - widgets library - Dart API
Interface for classes that register with the Widgets layer binding. When used as a mixin, provides no-op method implementations. See WidgetsBinding.addObserver and WidgetsBinding.removeObserver. This class can be extended directly, to get default behaviors
api.flutter.dev
기본 플러터 앱 라이프 사이클 상태 확인 샘플에 didChangePlatformBrightness 함수를 추가해서 확인한다.
class AppLifecycleReactor extends StatefulWidget {
const AppLifecycleReactor({ Key? key }) : super(key: key);
@override
_AppLifecycleReactorState createState() => _AppLifecycleReactorState();
}
class _AppLifecycleReactorState extends State<AppLifecycleReactor> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance!.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}
late AppLifecycleState _notification;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() { _notification = state; });
}
@override
Widget build(BuildContext context) {
return Text('Last notification: $_notification');
}
@override
void didChangePlatformBrightness() {
bool isDark = SchedulerBinding.instance.window.platformBrightness == Brightness.dark;
if (isDark) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.black
));
} else {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white
));
}
super.didChangePlatformBrightness();
}
}
반응형
'android' 카테고리의 다른 글
[Flutter] app/build.gradle def Class(FileInputStream, Properties, FileNotFoundException)가 Cannot resolve symbol 오류. (0) | 2022.01.15 |
---|---|
llvm Preprocessor 미리 정의 된 모든 매크로 확인 방법. (0) | 2021.06.15 |
[Flutter] 상단 상태바, 시스템 네비게이션바 색상 변경. (0) | 2021.05.30 |
[Flutter] 교육 앱, 만 13세 미만 아동을 주요 대상으로 제작된 앱 광고 설정. (0) | 2021.05.30 |
Android Studio, Kotlin Gradle and IDE plugins versions are different (0) | 2021.05.29 |