Skip to content

Commit

Permalink
fix: ios status bar theming
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Oct 5, 2022
1 parent 22748ec commit 73aa2f1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 52 deletions.
6 changes: 3 additions & 3 deletions lib/firebase_messaging_background_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import 'package:bluecherry_client/main.dart';

/// Notification buttons are not translated.
final snooze15ButtonLabel =
Platform.isIOS ? 'Snooze for 15 minutes' : '15 MINUTES';
Platform.isIOS ? 'Snooze for 15 minutes' : '15 minutes';
final snooze30ButtonLabel =
Platform.isIOS ? 'Snooze for 30 minutes' : '15 MINUTES';
final snooze60ButtonLabel = Platform.isIOS ? 'Snooze for 1 hour' : '1 HOUR';
Platform.isIOS ? 'Snooze for 30 minutes' : '15 minutes';
final snooze60ButtonLabel = Platform.isIOS ? 'Snooze for 1 hour' : '1 hour';

/// Callbacks received from the [FirebaseMessaging] instance.
Future<void> _firebaseMessagingHandler(RemoteMessage message) async {
Expand Down
16 changes: 16 additions & 0 deletions lib/utils/methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import 'dart:io';

import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';
import 'package:status_bar_control/status_bar_control.dart';

/// A helper singleton to set preferred orientation for the app.
class DeviceOrientations {
Expand All @@ -45,3 +48,16 @@ class DeviceOrientations {
/// Maintain a stack of the last set of orientations, to switch back to the most recent one.
final List<List<DeviceOrientation>> _stack = [];
}

/// Gets the correct [StatusBarStyle].
StatusBarStyle getStatusBarStyleFromBrightness(Brightness brightness) {
if (Platform.isIOS) {
return brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT;
} else {
return brightness == Brightness.dark
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT;
}
}
14 changes: 12 additions & 2 deletions lib/utils/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:status_bar_control/status_bar_control.dart';

import 'package:bluecherry_client/utils/methods.dart';

ThemeData createTheme({
ThemeMode themeMode = ThemeMode.light,
}) {
Expand Down Expand Up @@ -113,7 +115,15 @@ ThemeData createTheme({
);
}
StatusBarControl.setStyle(
isLight ? StatusBarStyle.DARK_CONTENT : StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(
Platform.isIOS
? isLight
? Brightness.light
: Brightness.dark
: isLight
? Brightness.dark
: Brightness.light,
),
);
return ThemeData(
// ignore: deprecated_member_use
Expand Down Expand Up @@ -220,7 +230,7 @@ ThemeData createTheme({
systemOverlayStyle: SystemUiOverlayStyle(
statusBarColor: isLight ? Colors.black12 : Colors.white12,
statusBarIconBrightness: isLight ? Brightness.dark : Brightness.light,
statusBarBrightness: isLight ? Brightness.dark : Brightness.light,
statusBarBrightness: isLight ? Brightness.light : Brightness.dark,
),
elevation: 4.0,
iconTheme: IconThemeData(
Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/add_server_wizard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class _AddServerWizardState extends State<AddServerWizard> {
value: const SystemUiOverlayStyle(
statusBarColor: Colors.white12,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.dark,
),
child: Scaffold(
resizeToAvoidBottomInset: false,
Expand Down Expand Up @@ -764,7 +765,7 @@ class _ConfigureDVRServerScreenState extends State<ConfigureDVRServerScreen> {
systemOverlayStyle: const SystemUiOverlayStyle(
statusBarColor: Colors.white12,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.light,
statusBarBrightness: Brightness.dark,
),
title: Text(
AppLocalizations.of(context).configure,
Expand Down Expand Up @@ -1008,7 +1009,7 @@ class _LetsGoScreenState extends State<LetsGoScreen> {
systemOverlayStyle: const SystemUiOverlayStyle(
statusBarColor: Colors.white12,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.light,
statusBarBrightness: Brightness.dark,
),
backgroundColor:
Theme.of(context).brightness == Brightness.light
Expand Down
10 changes: 3 additions & 7 deletions lib/widgets/device_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,7 @@ class _DeviceFullscreenViewerState extends State<DeviceFullscreenViewer> {
brightness = Theme.of(context).brightness;
await StatusBarControl.setHidden(true);
await StatusBarControl.setStyle(
brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(Theme.of(context).brightness),
);
DeviceOrientations.instance.set([
DeviceOrientation.landscapeLeft,
Expand All @@ -425,12 +423,10 @@ class _DeviceFullscreenViewerState extends State<DeviceFullscreenViewer> {
@override
void dispose() async {
widget.ijkPlayer?.removeListener(ijkPlayerListener);
if (widget.restoreStatusBarStyleOnDispose) {
if (widget.restoreStatusBarStyleOnDispose && brightness != null) {
await StatusBarControl.setHidden(false);
await StatusBarControl.setStyle(
brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(brightness!),
);
DeviceOrientations.instance.restoreLast();
}
Expand Down
32 changes: 11 additions & 21 deletions lib/widgets/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class _MobileHomeState extends State<MobileHome> {
if (tab == 0) {
await StatusBarControl.setHidden(true);
await StatusBarControl.setStyle(
Theme.of(context).brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(Theme.of(context).brightness),
);
DeviceOrientations.instance.set(
[
Expand All @@ -86,9 +84,7 @@ class _MobileHomeState extends State<MobileHome> {
// See #14.
await StatusBarControl.setHidden(false);
await StatusBarControl.setStyle(
Theme.of(context).brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(Theme.of(context).brightness),
);
DeviceOrientations.instance.set(
[
Expand All @@ -99,9 +95,7 @@ class _MobileHomeState extends State<MobileHome> {
} else if ([0, 3].contains(tab)) {
await StatusBarControl.setHidden(false);
await StatusBarControl.setStyle(
Theme.of(context).brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(Theme.of(context).brightness),
);
DeviceOrientations.instance.set(
DeviceOrientation.values,
Expand Down Expand Up @@ -185,9 +179,8 @@ class _MobileHomeState extends State<MobileHome> {
if (index == 0 && tab != 0) {
await StatusBarControl.setHidden(true);
await StatusBarControl.setStyle(
Theme.of(context).brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(
Theme.of(context).brightness),
);
DeviceOrientations.instance.set(
[
Expand All @@ -200,9 +193,8 @@ class _MobileHomeState extends State<MobileHome> {
// See #14.
await StatusBarControl.setHidden(false);
await StatusBarControl.setStyle(
Theme.of(context).brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(
Theme.of(context).brightness),
);
DeviceOrientations.instance.set(
[
Expand All @@ -214,9 +206,8 @@ class _MobileHomeState extends State<MobileHome> {
[0, 3].contains(tab)) {
await StatusBarControl.setHidden(false);
await StatusBarControl.setStyle(
Theme.of(context).brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(
Theme.of(context).brightness),
);
DeviceOrientations.instance.set(
DeviceOrientation.values,
Expand Down Expand Up @@ -265,9 +256,8 @@ class _MobileHomeState extends State<MobileHome> {
setState(() => tab = 0);
await StatusBarControl.setHidden(true);
await StatusBarControl.setStyle(
Theme.of(context).brightness == Brightness.light
? StatusBarStyle.DARK_CONTENT
: StatusBarStyle.LIGHT_CONTENT,
getStatusBarStyleFromBrightness(
Theme.of(context).brightness),
);
await SystemChrome.setPreferredOrientations(
[
Expand Down
23 changes: 6 additions & 17 deletions lib/widgets/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,12 @@ class NavigatorPopButton extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap ?? Navigator.of(context).pop,
borderRadius: BorderRadius.circular(20.0),
child: SizedBox(
height: 40.0,
width: 40.0,
child: Icon(
Icons.arrow_back,
size: 24.0,
color: color,
),
),
),
return IconButton(
splashRadius: 22.0,
onPressed: onTap ?? Navigator.of(context).pop,
icon: Icon(
Platform.isIOS ? Icons.arrow_back_ios : Icons.arrow_back,
color: color,
),
);
}
Expand Down

0 comments on commit 73aa2f1

Please sign in to comment.