fix: Auto unlock lock screen

This commit is contained in:
krille-chan 2024-06-07 12:23:09 +02:00
commit cdf2b14f30
No known key found for this signature in database

View file

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -20,14 +21,14 @@ class _LockScreenState extends State<LockScreen> {
bool _inputBlocked = false; bool _inputBlocked = false;
final TextEditingController _textEditingController = TextEditingController(); final TextEditingController _textEditingController = TextEditingController();
void tryUnlock(BuildContext context) async { void tryUnlock(String text) async {
setState(() { setState(() {
_errorText = null; _errorText = null;
}); });
if (_textEditingController.text.length < 4) return; if (text.length < 4) return;
final enteredPin = int.tryParse(_textEditingController.text); final enteredPin = int.tryParse(text);
if (enteredPin == null || _textEditingController.text.length != 4) { if (enteredPin == null || text.length != 4) {
setState(() { setState(() {
_errorText = L10n.of(context)!.invalidInput; _errorText = L10n.of(context)!.invalidInput;
}); });
@ -90,9 +91,12 @@ class _LockScreenState extends State<LockScreen> {
autofocus: true, autofocus: true,
textAlign: TextAlign.center, textAlign: TextAlign.center,
readOnly: _inputBlocked, readOnly: _inputBlocked,
onChanged: (_) => tryUnlock(context), onChanged: tryUnlock,
onSubmitted: (_) => tryUnlock(context), onSubmitted: tryUnlock,
style: const TextStyle(fontSize: 40), style: const TextStyle(fontSize: 40),
inputFormatters: [
LengthLimitingTextInputFormatter(4),
],
decoration: InputDecoration( decoration: InputDecoration(
errorText: _errorText, errorText: _errorText,
hintText: '****', hintText: '****',