feat: add biometric authentication support and related UI screens

- Updated AndroidManifest.xml to include permissions for biometric authentication.
- Changed MainActivity to extend FlutterFragmentActivity for better compatibility.
- Modified gradle.properties to optimize memory settings.
- Enhanced app.dart to manage new app phases for biometric authentication.
- Implemented LocalVaultService methods for handling biometric key protection.
- Created BiometricChoiceScreen and BiometricGateScreen for user interaction.
- Updated HomeScreen to handle vault invalidation scenarios.
- Registered local_auth plugin for biometric functionality on macOS and Windows.
- Updated pubspec.yaml and pubspec.lock to include local_auth dependency.
This commit is contained in:
2026-05-17 13:48:09 +02:00
parent 2141009d36
commit 2160478fa7
13 changed files with 910 additions and 63 deletions
+120
View File
@@ -0,0 +1,120 @@
import 'package:flutter/material.dart';
import 'package:notas/widgets/app_title_bar.dart';
class BiometricChoiceScreen extends StatelessWidget {
const BiometricChoiceScreen({
super.key,
required this.isBusy,
required this.onEnableBiometrics,
required this.onSkipBiometrics,
});
final bool isBusy;
final Future<void> Function() onEnableBiometrics;
final Future<void> Function() onSkipBiometrics;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF191A1D),
Color(0xFF222326),
Color(0xFF101114),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: SafeArea(
child: Column(
children: [
const AppTitleBar(),
Expanded(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 460),
child: Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: const Color(0xFF1D1E20),
borderRadius: BorderRadius.circular(24),
border: Border.all(color: Colors.white.withValues(alpha: 0.08)),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.35),
blurRadius: 30,
offset: const Offset(0, 18),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Icon(
Icons.fingerprint,
color: Colors.amber,
size: 44,
),
const SizedBox(height: 16),
const Text(
'Proteger con huella',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 10),
Text(
'¿Quieres que la app te pida huella o cara antes de entrar a tus notas?',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white.withValues(alpha: 0.72),
height: 1.4,
),
),
const SizedBox(height: 22),
FilledButton(
onPressed: isBusy ? null : onEnableBiometrics,
style: FilledButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14),
),
child: isBusy
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Sí, activar huella'),
),
const SizedBox(height: 10),
OutlinedButton(
onPressed: isBusy ? null : onSkipBiometrics,
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14),
side: const BorderSide(color: Colors.white24),
foregroundColor: Colors.white,
),
child: const Text('No, entrar sin huella'),
),
],
),
),
),
),
),
),
],
),
),
),
);
}
}
+134
View File
@@ -0,0 +1,134 @@
import 'package:flutter/material.dart';
import 'package:notas/widgets/app_title_bar.dart';
class BiometricGateScreen extends StatefulWidget {
const BiometricGateScreen({
super.key,
required this.isBusy,
required this.onUnlockRequested,
});
final bool isBusy;
final Future<void> Function() onUnlockRequested;
@override
State<BiometricGateScreen> createState() => _BiometricGateScreenState();
}
class _BiometricGateScreenState extends State<BiometricGateScreen> {
bool _autoRequested = false;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
_requestUnlockOnce();
}
});
}
Future<void> _requestUnlockOnce() async {
if (_autoRequested || widget.isBusy) {
return;
}
_autoRequested = true;
await widget.onUnlockRequested();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF191A1D),
Color(0xFF222326),
Color(0xFF101114),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: SafeArea(
child: Column(
children: [
const AppTitleBar(),
Expanded(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 460),
child: Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: const Color(0xFF1D1E20),
borderRadius: BorderRadius.circular(24),
border: Border.all(color: Colors.white.withValues(alpha: 0.08)),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.35),
blurRadius: 30,
offset: const Offset(0, 18),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Icon(
Icons.fingerprint,
color: Colors.amber,
size: 44,
),
const SizedBox(height: 16),
const Text(
'Desbloqueo biométrico',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 10),
Text(
'Pon tu huella o cara para entrar a tus notas.',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white.withValues(alpha: 0.72),
height: 1.4,
),
),
const SizedBox(height: 22),
FilledButton(
onPressed: widget.isBusy ? null : widget.onUnlockRequested,
style: FilledButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14),
),
child: widget.isBusy
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Desbloquear'),
),
],
),
),
),
),
),
),
],
),
),
),
);
}
}
+15 -8
View File
@@ -15,10 +15,12 @@ class HomeScreen extends StatefulWidget {
super.key,
required this.repository,
required this.onOpenSettings,
this.onVaultInvalid,
});
final NoteRepository repository;
final VoidCallback onOpenSettings;
final Future<void> Function()? onVaultInvalid;
@override
State<HomeScreen> createState() => _HomeScreenState();
@@ -38,16 +40,21 @@ class _HomeScreenState extends State<HomeScreen> {
}
Future<void> _loadNotes() async {
final List<Note> storedNotes = await widget.repository.loadNotes();
try {
final List<Note> storedNotes = await widget.repository.loadNotes();
if (!mounted) {
return;
if (!mounted) return;
setState(() {
_notes = storedNotes;
_isLoading = false;
});
} catch (e) {
// If loading notes fails (e.g., DB corrupt), notify the app to reset the vault.
if (widget.onVaultInvalid != null) {
await widget.onVaultInvalid!();
}
}
setState(() {
_notes = storedNotes;
_isLoading = false;
});
}
Future<void> _openNoteComposer() async {