Skip to content

Commit 2326c85

Browse files
committed
App status bar theme
1 parent 2a24ce6 commit 2326c85

3 files changed

Lines changed: 48 additions & 31 deletions

File tree

lib/main.dart

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import 'package:piwigo_ng/app.dart';
88
import 'package:piwigo_ng/services/auto_upload_manager.dart';
99
import 'package:piwigo_ng/services/notification_service.dart';
1010
import 'package:piwigo_ng/services/preferences_service.dart';
11+
import 'package:piwigo_ng/services/theme_provider.dart';
1112
import 'package:shared_preferences/shared_preferences.dart';
1213

1314
void main() async {
1415
WidgetsFlutterBinding.ensureInitialized();
1516
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
16-
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
17-
systemNavigationBarColor: Colors.black.withOpacity(0.1),
18-
statusBarColor: Colors.black.withOpacity(0.1),
19-
));
17+
_setUITheme();
2018
HttpOverrides.global = SSLHttpOverrides();
2119
appPreferences = await SharedPreferences.getInstance();
2220
runApp(const App());
@@ -25,11 +23,23 @@ void main() async {
2523
initializeWorkManager();
2624
}
2725

28-
void _clearUnusedStorage() async {
26+
Future<void> _clearUnusedStorage() async {
2927
SharedPreferences prefs = await SharedPreferences.getInstance();
30-
if (!prefs.containsKey('STORAGE_VERSION') && prefs.getString('STORAGE_VERSION') != '2.0.0') {
28+
if (!prefs.containsKey('STORAGE_VERSION') &&
29+
prefs.getString('STORAGE_VERSION') != '2.0.0') {
3130
prefs.clear();
3231
const FlutterSecureStorage().deleteAll();
3332
prefs.setString('STORAGE_VERSION', '2.0.0');
3433
}
3534
}
35+
36+
Future<void> _setUITheme() async {
37+
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
38+
bool isDark = sharedPreferences.getBool(ThemeNotifier.themeKey) ??
39+
(ThemeMode.system == ThemeMode.dark);
40+
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
41+
systemNavigationBarColor: Colors.black.withOpacity(0.001),
42+
statusBarColor: Colors.black.withOpacity(0.001),
43+
statusBarIconBrightness: isDark ? Brightness.light : Brightness.dark,
44+
));
45+
}

lib/services/theme_provider.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
22
import 'package:shared_preferences/shared_preferences.dart';
33

44
class ThemeNotifier extends ChangeNotifier {
5-
final String _themeKey = "THEME";
5+
static const String themeKey = 'THEME';
66
late bool _isDark;
77
bool get isDark => _isDark;
88

99
ThemeNotifier() {
1010
getTheme();
11-
_isDark = ThemeMode.system == ThemeMode.dark;
11+
// _isDark = ThemeMode.system == ThemeMode.dark;
1212
}
1313

1414
toggleTheme() {
@@ -19,12 +19,12 @@ class ThemeNotifier extends ChangeNotifier {
1919

2020
setTheme() async {
2121
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
22-
sharedPreferences.setBool(_themeKey, _isDark);
22+
sharedPreferences.setBool(themeKey, _isDark);
2323
}
2424

2525
getTheme() async {
2626
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
27-
_isDark = sharedPreferences.getBool(_themeKey) ??
27+
_isDark = sharedPreferences.getBool(themeKey) ??
2828
(ThemeMode.system == ThemeMode.dark);
2929
notifyListeners();
3030
}

lib/views/image/image_view_page.dart

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ import 'package:photo_view/photo_view_gallery.dart';
99
import 'package:piwigo_ng/api/api_client.dart';
1010
import 'package:piwigo_ng/api/api_error.dart';
1111
import 'package:piwigo_ng/api/images.dart';
12+
import 'package:piwigo_ng/app.dart';
1213
import 'package:piwigo_ng/components/dialogs/image_comment_dialog.dart';
1314
import 'package:piwigo_ng/components/popup_list_item.dart';
1415
import 'package:piwigo_ng/models/album_model.dart';
1516
import 'package:piwigo_ng/models/image_model.dart';
1617
import 'package:piwigo_ng/models/tag_model.dart';
1718
import 'package:piwigo_ng/services/preferences_service.dart';
19+
import 'package:piwigo_ng/services/theme_provider.dart';
1820
import 'package:piwigo_ng/utils/image_actions.dart';
1921
import 'package:piwigo_ng/utils/localizations.dart';
2022
import 'package:piwigo_ng/utils/resources.dart';
2123
import 'package:piwigo_ng/views/image/video_player_page.dart';
24+
import 'package:provider/provider.dart';
2225

2326
/// Media Full Screen page
2427
/// * Video player
@@ -85,7 +88,10 @@ class _ImageViewPageState extends State<ImageViewPage> {
8588
}
8689
}
8790
_pageController = PageController(initialPage: _page);
88-
91+
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
92+
systemNavigationBarColor: Colors.black.withOpacity(0.1),
93+
statusBarColor: Colors.black.withOpacity(0.1),
94+
));
8995
_loadCookies();
9096
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
9197
_getImagesInfo(_imageList);
@@ -96,6 +102,14 @@ class _ImageViewPageState extends State<ImageViewPage> {
96102
@override
97103
void dispose() {
98104
_pageController.dispose();
105+
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
106+
systemNavigationBarColor: Colors.black.withOpacity(0.001),
107+
statusBarColor: Colors.black.withOpacity(0.001),
108+
statusBarIconBrightness:
109+
App.appKey.currentContext?.read<ThemeNotifier>().isDark ?? false
110+
? Brightness.light
111+
: Brightness.dark,
112+
));
99113
super.dispose();
100114
}
101115

@@ -233,26 +247,19 @@ class _ImageViewPageState extends State<ImageViewPage> {
233247
Widget build(BuildContext context) {
234248
return WillPopScope(
235249
onWillPop: _onWillPop,
236-
child: AnnotatedRegion<SystemUiOverlayStyle>(
237-
/// Changes System overlay colors to match black background
238-
value: SystemUiOverlayStyle.light.copyWith(
239-
systemNavigationBarColor: Colors.black.withOpacity(0.1),
240-
statusBarColor: Colors.black.withOpacity(0.1),
241-
),
242-
child: Scaffold(
243-
backgroundColor: Colors.black,
244-
resizeToAvoidBottomInset: true,
245-
extendBodyBehindAppBar: true,
246-
extendBody: true,
247-
primary: false,
248-
body: SafeArea(
249-
child: Stack(
250-
children: [
251-
_content,
252-
_top,
253-
_bottom,
254-
],
255-
),
250+
child: Scaffold(
251+
backgroundColor: Colors.black,
252+
resizeToAvoidBottomInset: true,
253+
extendBodyBehindAppBar: true,
254+
extendBody: true,
255+
primary: false,
256+
body: SafeArea(
257+
child: Stack(
258+
children: [
259+
_content,
260+
_top,
261+
_bottom,
262+
],
256263
),
257264
),
258265
),

0 commit comments

Comments
 (0)