diff --git a/lib/widgets/app_lock.dart b/lib/widgets/app_lock.dart index c6ecde5385..6a094084a1 100644 --- a/lib/widgets/app_lock.dart +++ b/lib/widgets/app_lock.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:matrix/matrix.dart'; import 'package:provider/provider.dart'; import 'package:fluffychat/config/setting_keys.dart'; @@ -11,9 +12,11 @@ class AppLockWidget extends StatefulWidget { const AppLockWidget({ required this.child, required this.pincode, + required this.clients, super.key, }); + final List clients; final String? pincode; final Widget child; @@ -35,6 +38,16 @@ class AppLock extends State with WidgetsBindingObserver { _isLocked = isActive; super.initState(); WidgetsBinding.instance.addObserver(this); + WidgetsBinding.instance.addPostFrameCallback(_checkLoggedIn); + } + + void _checkLoggedIn(_) async { + if (widget.clients.any((client) => client.isLogged())) return; + + await changePincode(null); + setState(() { + _isLocked = false; + }); } @override @@ -60,7 +73,7 @@ class AppLock extends State with WidgetsBindingObserver { return; } - bool unlock(String? pincode) { + bool unlock(String pincode) { final isCorrect = pincode == _pincode; if (isCorrect) { setState(() { diff --git a/lib/widgets/fluffy_chat_app.dart b/lib/widgets/fluffy_chat_app.dart index eb9f0f6579..ee55a2f13d 100644 --- a/lib/widgets/fluffy_chat_app.dart +++ b/lib/widgets/fluffy_chat_app.dart @@ -48,6 +48,7 @@ class FluffyChatApp extends StatelessWidget { routerConfig: router, builder: (context, child) => AppLockWidget( pincode: pincode, + clients: clients, child: Matrix( clients: clients, child: testWidget ?? child, diff --git a/lib/widgets/lock_screen.dart b/lib/widgets/lock_screen.dart index decea531a3..8825f6cd8c 100644 --- a/lib/widgets/lock_screen.dart +++ b/lib/widgets/lock_screen.dart @@ -7,7 +7,6 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/config/themes.dart'; import 'package:fluffychat/widgets/app_lock.dart'; -import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/theme_builder.dart'; class LockScreen extends StatefulWidget { @@ -23,20 +22,6 @@ class _LockScreenState extends State { bool _inputBlocked = false; final TextEditingController _textEditingController = TextEditingController(); - @override - void initState() { - super.initState(); - _checkLoggedIn(); - } - - void _checkLoggedIn() async { - if (Matrix.of(context).client.isLogged()) return; - - final appLock = AppLock.of(context); - await appLock.changePincode(null); - appLock.unlock(null); - } - void tryUnlock(BuildContext context) async { setState(() { _errorText = null;