mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
add authorization
This commit is contained in:
60
lib/pages/auth_page.dart
Normal file
60
lib/pages/auth_page.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
|
||||
class AuthPage extends StatefulWidget {
|
||||
const AuthPage({super.key, this.onSuccessfulAuth});
|
||||
|
||||
final void Function()? onSuccessfulAuth;
|
||||
|
||||
@override
|
||||
State<AuthPage> createState() => _AuthPageState();
|
||||
}
|
||||
|
||||
class _AuthPageState extends State<AuthPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) {
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
},
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.security, size: 36),
|
||||
const SizedBox(height: 16),
|
||||
Text("Authentication Required".tl),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton(
|
||||
onPressed: auth,
|
||||
child: Text("Continue".tl),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void auth() async {
|
||||
var localAuth = LocalAuthentication();
|
||||
var canCheckBiometrics = await localAuth.canCheckBiometrics;
|
||||
if (!canCheckBiometrics && !await localAuth.isDeviceSupported()) {
|
||||
widget.onSuccessfulAuth?.call();
|
||||
return;
|
||||
}
|
||||
var isAuthorized = await localAuth.authenticate(
|
||||
localizedReason: "Please authenticate to continue".tl,
|
||||
);
|
||||
if (isAuthorized) {
|
||||
widget.onSuccessfulAuth?.call();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user