π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Sync lock screen theme changes
Neeraj Gupta9aa1d29f6be0
diff --git a/mobile/apps/auth/lib/ui/settings/theme_switch_widget.dart b/mobile/apps/auth/lib/ui/settings/theme_switch_widget.dartindex 08e6b317f2..4d63e1db2e 100644--- a/mobile/apps/auth/lib/ui/settings/theme_switch_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/theme_switch_widget.dart@@ -6,6 +6,7 @@ import 'package:ente_auth/ui/components/captioned_text_widget.dart';import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';import 'package:ente_auth/ui/components/menu_item_widget.dart';import 'package:ente_auth/ui/settings/common_settings.dart';+import 'package:ente_lock_screen/ui/app_lock.dart';import 'package:flutter/material.dart';class ThemeSwitchWidget extends StatefulWidget {@@ -84,6 +85,7 @@ class _ThemeSwitchWidgetState extends State<ThemeSwitchWidget> {onTap: () async {final adaptiveTheme = AdaptiveTheme.of(context);adaptiveTheme.setThemeMode(themeMode);+ AppLock.of(context)?.setThemeMode(_themeMode(themeMode));await adaptiveTheme.persist();currentThemeMode = themeMode;if (mounted) {@@ -92,4 +94,10 @@ class _ThemeSwitchWidgetState extends State<ThemeSwitchWidget> {},);}++ ThemeMode _themeMode(AdaptiveThemeMode themeMode) {+ if (themeMode.isLight) return ThemeMode.light;+ if (themeMode.isDark) return ThemeMode.dark;+ return ThemeMode.system;+ }}diff --git a/mobile/packages/lock_screen/lib/ui/app_lock.dart b/mobile/packages/lock_screen/lib/ui/app_lock.dartindex 67c2da4b73..43a0bbe1b7 100644--- a/mobile/packages/lock_screen/lib/ui/app_lock.dart+++ b/mobile/packages/lock_screen/lib/ui/app_lock.dart@@ -66,6 +66,7 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {late bool _didUnlockForAppLaunch;late bool _isLocked;late bool _enabled;+ late ThemeMode _themeMode;Timer? _backgroundLockLatencyTimer;@@ -78,6 +79,7 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {this._didUnlockForAppLaunch = !this.widget.enabled;this._isLocked = false;this._enabled = this.widget.enabled;+ this._themeMode = this.widget.savedThemeMode;}@override@@ -115,7 +117,7 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {return MaterialApp(home: this.widget.enabled ? this._lockScreen : this.widget.builder(null),navigatorKey: _navigatorKey,- themeMode: widget.savedThemeMode,+ themeMode: this._themeMode,theme: widget.lightTheme,darkTheme: widget.darkTheme,locale: widget.locale,@@ -176,6 +178,15 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {}}+ void setThemeMode(ThemeMode themeMode) {+ if (this._themeMode == themeMode) {+ return;+ }+ setState(() {+ this._themeMode = themeMode;+ });+ }+/// Makes sure that [AppLock] shows the [lockScreen] on subsequent app pauses.void enable() {setState(() {diff --git a/mobile/packages/lock_screen/test/app_lock_test.dart b/mobile/packages/lock_screen/test/app_lock_test.dartnew file mode 100644index 0000000000..525469a0dc--- /dev/null+++ b/mobile/packages/lock_screen/test/app_lock_test.dart@@ -0,0 +1,40 @@+import 'package:ente_lock_screen/ui/app_lock.dart';+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';++void main() {+ testWidgets('updates theme mode after startup', (tester) async {+ await tester.pumpWidget(+ AppLock(+ builder: (_) => Builder(+ builder: (context) => Column(+ children: [+ Text(Theme.of(context).brightness.name),+ TextButton(+ onPressed: () =>+ AppLock.of(context)!.setThemeMode(ThemeMode.light),+ child: const Text('Use light'),+ ),+ ],+ ),+ ),+ lockScreen: const SizedBox.shrink(),+ enabled: false,+ savedThemeMode: ThemeMode.dark,+ lightTheme: ThemeData(brightness: Brightness.light),+ darkTheme: ThemeData(brightness: Brightness.dark),+ supportedLocales: const [Locale('en')],+ localizationsDelegates: const <LocalizationsDelegate<dynamic>>[],+ localeListResolutionCallback: (_, supportedLocales) =>+ supportedLocales.first,+ ),+ );++ expect(find.text('dark'), findsOneWidget);++ await tester.tap(find.text('Use light'));+ await tester.pumpAndSettle();++ expect(find.text('light'), findsOneWidget);+ });+}