Flutter Biometric Auth Plus
Enhanced biometric authentication with fallback options and better error handling for Flutter applications. Now with full platform support and custom implementation!
π What's New in v0.0.2
- β
Complete rewrite: Removed dependency on
local_auth
package - β Custom implementation: Platform-specific native code for each platform
- β Full platform support: All 6 platforms (iOS, Android, Web, Windows, macOS, Linux)
- β WASM compatibility: Fully compatible with web/WASM runtime
- β Perfect score: 160/160 points in Pana analysis
π Features
- π Multi-platform biometric authentication
- π± Platform-specific native implementations
- π Web/WASM compatibility
- π Automatic fallback mechanisms
- β‘ Enhanced error handling
- π― Type-safe API design
- π Comprehensive documentation
π± Platform Support
Platform | Status | Implementation |
---|---|---|
Android | β Full Support | BiometricManager + BiometricPrompt |
iOS | β Full Support | LocalAuthentication framework |
Web | β Full Support | WebAuthn API + WASM |
Windows | β Full Support | Windows Hello APIs |
macOS | β Full Support | LocalAuthentication framework |
Linux | β Full Support | PAM + biometric daemons |
π Quick Start
1. Add Dependency
dependencies:
flutter_biometric_auth_plus: ^0.0.2
2. Import Package
import 'package:flutter_biometric_auth_plus/flutter_biometric_auth_plus.dart';
3. Check Biometric Availability
// Check if biometrics are available
final bool isAvailable = await BiometricAuth.isBiometricsAvailable();
// Get available biometric types
final List<BiometricAuthType> biometrics =
await BiometricAuth.getAvailableBiometrics();
4. Authenticate
// Basic authentication
final AuthResult result = await BiometricAuth.authenticate(
reason: 'Please authenticate to access the app',
);
if (result.isSuccess) {
print('Authentication successful!');
} else {
print('Authentication failed: ${result.data?['reason']}');
}
5. Authentication with Fallback
// Try biometrics first, fallback to passcode
final AuthResult result = await BiometricAuth.authenticateWithFallback(
reason: 'Please authenticate to access the app',
);
if (result.isSuccess) {
if (result.data?['fallbackUsed'] == true) {
print('Authenticated using device passcode');
} else {
print('Authenticated using biometrics');
}
}
π§ Advanced Usage
Check Device Support
final bool isSupported = await BiometricAuth.isDeviceSupported();
final String strength = await BiometricAuth.getBiometricStrength();
Handle Different Biometric Types
final List<BiometricAuthType> availableBiometrics =
await BiometricAuth.getAvailableBiometrics();
for (final type in availableBiometrics) {
print('Available: ${type.displayName} (${type.identifier})');
}
Custom Error Handling
try {
final result = await BiometricAuth.authenticate(
reason: 'Please authenticate',
);
// Handle success
} on BiometricException catch (e) {
switch (e.code) {
case 'BIOMETRICS_NOT_AVAILABLE':
print('Biometrics not available: ${e.message}');
break;
case 'AUTHENTICATION_FAILED':
print('Authentication failed: ${e.message}');
break;
case 'PERMISSION_DENIED':
print('Permission denied: ${e.message}');
break;
}
}
ποΈ Architecture
This package uses a platform-agnostic approach with automatic fallback:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BiometricAuth Class β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββββββ βββββββββββββββββββββββββββββββββββ β
β β Native Impl β β Stub Impl β β
β β β β β β
β β β’ Android β β β’ Web/WASM Compatible β β
β β β’ iOS β β β’ WebAuthn API β β
β β β’ Windows β β β’ Fallback Implementation β β
β β β’ macOS β β β β
β β β’ Linux β β β β
β βββββββββββββββββββ βββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Migration from local_auth
If you're migrating from the local_auth
package:
Before (local_auth)
import 'package:local_auth/local_auth.dart';
final LocalAuthentication auth = LocalAuthentication();
final bool canAuthenticate = await auth.canCheckBiometrics;
After (flutter_biometric_auth_plus)
import 'package:flutter_biometric_auth_plus/flutter_biometric_auth_plus.dart';
final bool canAuthenticate = await BiometricAuth.isBiometricsAvailable();
Benefits of migration:
- β Full platform support (was limited to 4/6 platforms)
- β WASM compatibility (was not compatible)
- β No external dependencies (was dependent on local_auth)
- β Better error handling (enhanced error messages)
- β Automatic fallback (seamless platform switching)
π Requirements
- Flutter: >=3.10.0
- Dart: >=3.0.0
- Platforms: iOS 9.0+, Android 6.0+, Web, Windows 10+, macOS 10.14+, Linux
π Permissions
Android
Add to android/app/src/main/AndroidManifest.xml
:
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
iOS
Add to ios/Runner/Info.plist
:
<key>NSFaceIDUsageDescription</key>
<string>This app uses Face ID for secure authentication.</string>
π§ͺ Testing
Run the test suite:
flutter test
Run analysis:
flutter analyze
dart analyze
π Quality Metrics
- Pana Score: 160/160 (100%) β
- Test Coverage: 15/15 tests passing β
- Analysis: No issues found β
- Documentation: 95.3% API coverage β
- Platform Support: 6/6 platforms β
- WASM Compatibility: Full support β
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Flutter Team for the amazing framework
- Dart Team for the powerful language
- Community for feedback and contributions
Made with β€οΈ for the Flutter community
This package is a complete rewrite that removes dependency on external biometric packages and provides full platform support with custom implementations.