fix: Auto unlock lock screen
This commit is contained in:
parent
fd084d9ed3
commit
cdf2b14f30
1 changed files with 10 additions and 6 deletions
|
|
@ -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: '****',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue