From 7c59b2598354606531987e8de08d75a2881bd153 Mon Sep 17 00:00:00 2001 From: hackerhgl Date: Wed, 23 Dec 2020 09:14:27 +0500 Subject: [PATCH] Status Bar handler config --- lib/configs/App.dart | 4 ++- lib/configs/StatusBar.dart | 51 ++++++++++++++++++++++++++++++++++++++ lib/main.firebase.dart | 2 ++ lib/screens/Home/Home.dart | 21 ++++++++++++++-- lib/utils/UIUtils.dart | 2 ++ 5 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 lib/configs/StatusBar.dart diff --git a/lib/configs/App.dart b/lib/configs/App.dart index ee2b2e8..3afaf0a 100644 --- a/lib/configs/App.dart +++ b/lib/configs/App.dart @@ -5,6 +5,7 @@ import 'AppDimensions.dart'; import 'TextStyles.dart'; import 'CommonProps.dart'; import 'AppTheme.dart'; +import 'StatusBar.dart'; class App { static BuildContext ctx; @@ -17,7 +18,8 @@ class App { TextStyles.init(); CommonProps.init(); App.ctx = context; - + // final route = ModalRoute.of(context).settings.name; + // StatusBarHandler.init(context, route); isLtr = Directionality.of(context) == TextDirection.ltr; } diff --git a/lib/configs/StatusBar.dart b/lib/configs/StatusBar.dart new file mode 100644 index 0000000..2fdc49c --- /dev/null +++ b/lib/configs/StatusBar.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_uis/AppRoutes.dart'; +import 'package:flutter_uis/utils/UIUtils.dart'; + +const MODE = 'mode'; +const LIGHT = 'light'; +const DARK = 'dark'; + +final statusBarMap = { + AppRoutes.home: MODE, + AppRoutes.about: MODE, + AppRoutes.aboutDeveloper: MODE, + AppRoutes.download: MODE, + AppRoutes.uiList: MODE, + AppRoutes.uiDetail: LIGHT, + AppRoutes.designerProfile: LIGHT, + + // Healthy Food Delivery + AppRoutes.hfdHome: MODE, + AppRoutes.hfdDetail: MODE, + + // Hot Air Balloon + AppRoutes.habHome: MODE, + AppRoutes.habDetail: MODE, + + // Sky View + AppRoutes.skvHome: MODE, + AppRoutes.skvDetail: MODE, + + AppRoutes.ascHome: MODE, + + AppRoutes.etcHome: MODE, +}; + +class StatusBarHandler { + static init(BuildContext context, String route) { + final theme = statusBarMap[route]; + print("$route $theme"); + switch (theme) { + case DARK: + UIUtils.darkStatusBar(); + break; + case LIGHT: + print("LIGHT"); + UIUtils.lightStatusBar(); + break; + default: + UIUtils.themeStatusBar(context); + } + } +} diff --git a/lib/main.firebase.dart b/lib/main.firebase.dart index 793bb54..931ba8b 100644 --- a/lib/main.firebase.dart +++ b/lib/main.firebase.dart @@ -3,6 +3,7 @@ import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_analytics/observer.dart'; +import 'package:flutter_uis/utils/UIUtils.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive/hive.dart'; @@ -14,6 +15,7 @@ void main() async { await Firebase.initializeApp(); await Hive.initFlutter(); await Hive.openBox('app'); + UIUtils.lightStatusBar(); final List observers = []; diff --git a/lib/screens/Home/Home.dart b/lib/screens/Home/Home.dart index 22e7d90..06e76fe 100644 --- a/lib/screens/Home/Home.dart +++ b/lib/screens/Home/Home.dart @@ -1,5 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_uis/configs/App.dart'; import 'package:flutter_uis/utils/UIUtils.dart'; @@ -19,12 +20,28 @@ class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { Dimensions.init(context); - UIUtils.themeStatusBar(context); + bool toggle = false; return ChangeNotifierProvider( create: (_) => HomeStateProvider(), child: Screen( child: SafeArea( - child: HomeBody(), + child: Column( + children: [ + HomeBody(), + // RaisedButton( + // onPressed: () { + // toggle = !toggle; + // print('UIUtils $toggle'); + // if (toggle) { + // UIUtils.lightStatusBar(); + // } else { + // UIUtils.darkStatusBar(); + // } + // }, + // child: Text("TOGGLE"), + // ), + ], + ), ), overlayBuilders: [ Selector( diff --git a/lib/utils/UIUtils.dart b/lib/utils/UIUtils.dart index 4fb22a6..7638e4e 100644 --- a/lib/utils/UIUtils.dart +++ b/lib/utils/UIUtils.dart @@ -31,6 +31,7 @@ class UIUtils { static lightStatusBar() { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith( + statusBarBrightness: Brightness.light, statusBarIconBrightness: Brightness.light, systemNavigationBarIconBrightness: Brightness.light, )); @@ -38,6 +39,7 @@ class UIUtils { static darkStatusBar() { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith( + statusBarBrightness: Brightness.dark, statusBarIconBrightness: Brightness.dark, // systemNavigationBarIconBrightness: Brightness.dark, ));