Skip to content

Commit

Permalink
Status Bar handler config
Browse files Browse the repository at this point in the history
  • Loading branch information
hmziqrs committed Dec 23, 2020
1 parent 1c7deaf commit 7c59b25
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/configs/App.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'AppDimensions.dart';
import 'TextStyles.dart';
import 'CommonProps.dart';
import 'AppTheme.dart';
import 'StatusBar.dart';

class App {
static BuildContext ctx;
Expand All @@ -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;
}

Expand Down
51 changes: 51 additions & 0 deletions lib/configs/StatusBar.dart
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 2 additions & 0 deletions lib/main.firebase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -14,6 +15,7 @@ void main() async {
await Firebase.initializeApp();
await Hive.initFlutter();
await Hive.openBox('app');
UIUtils.lightStatusBar();

final List<NavigatorObserver> observers = [];

Expand Down
21 changes: 19 additions & 2 deletions lib/screens/Home/Home.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -19,12 +20,28 @@ class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
Dimensions.init(context);
UIUtils.themeStatusBar(context);
bool toggle = false;
return ChangeNotifierProvider<HomeStateProvider>(
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<HomeStateProvider, bool>(
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/UIUtils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class UIUtils {

static lightStatusBar() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.light,
systemNavigationBarIconBrightness: Brightness.light,
));
}

static darkStatusBar() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
statusBarBrightness: Brightness.dark,
statusBarIconBrightness: Brightness.dark,
// systemNavigationBarIconBrightness: Brightness.dark,
));
Expand Down

0 comments on commit 7c59b25

Please sign in to comment.