ente/lib/ui/lock_screen.dart

81 lines
2.2 KiB
Dart
Raw Normal View History

2021-03-21 06:27:42 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
2021-03-21 08:32:10 +00:00
import 'package:logging/logging.dart';
import 'package:photos/ui/app_lock.dart';
2021-03-21 06:27:42 +00:00
import 'package:photos/ui/loading_widget.dart';
import 'package:photos/utils/auth_util.dart';
class LockScreen extends StatefulWidget {
LockScreen({Key key}) : super(key: key);
@override
_LockScreenState createState() => _LockScreenState();
}
class _LockScreenState extends State<LockScreen> {
2021-03-21 08:32:10 +00:00
final _logger = Logger("LockScreen");
bool _isUnlocking = true;
@override
void initState() {
_showLockScreen();
super.initState();
}
2021-03-21 06:27:42 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
2021-03-21 08:32:10 +00:00
width: double.infinity,
height: 64,
padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
child: _isUnlocking
? Padding(
padding: const EdgeInsets.only(top: 24),
child: loadWidget,
)
: RaisedButton(
child: Text(
"unlock",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
letterSpacing: 1.0,
),
textAlign: TextAlign.center,
2021-03-21 06:27:42 +00:00
),
2021-03-21 08:32:10 +00:00
onPressed: () async {
2021-03-21 06:27:42 +00:00
setState(() {
2021-03-21 08:32:10 +00:00
_isUnlocking = true;
2021-03-21 06:27:42 +00:00
});
2021-03-21 08:32:10 +00:00
_showLockScreen();
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
)),
2021-03-21 06:27:42 +00:00
),
);
}
2021-03-21 08:32:10 +00:00
Future<void> _showLockScreen() async {
_logger.info("Showing lockscreen");
try {
final result = await requestAuthentication();
if (result) {
AppLock.of(context).didUnlock();
} else {
setState(() {
_isUnlocking = false;
});
}
} catch (e) {
_logger.severe(e);
setState(() {
_isUnlocking = false;
});
}
}
2021-03-21 06:27:42 +00:00
}