flutter_app_lock_pro

pub package

Pro app lock for Flutter: lock specific screens, auto-lock timer, PIN / pattern / biometric, wrong-attempt protection, screenshot protection, and background blur. Built for banking, crypto, and fintech apps.

Features

Feature Description
Lock specific screens Protect routes like /wallet, /profile, /settings
Auto-lock timer Lock automatically after inactivity (e.g. 2 minutes)
Screenshot protection Disable screenshots & screen recording (Android FLAG_SECURE; iOS blur when captured)
Wrong-attempt protection After N wrong PIN attempts, block for a duration (e.g. 5 attempts → 5 min block)
Multiple unlock methods PIN, biometric (fingerprint / Face ID)
Background blur Blur app when in app switcher / recents
Lock API AppLock.lockNow(), AppLock.unlock(), AppLock.isLocked()

Installation

dependencies:
  flutter_app_lock_pro: ^1.0.0
flutter pub get

iOS

Add to ios/Runner/Info.plist for Face ID:

<key>NSFaceIDUsageDescription</key>
<string>Unlock the app with Face ID</string>

Android

Uses FLAG_SECURE and lifecycle observers; no extra setup.

Usage

1. Enable app lock at startup

import 'package:flutter_app_lock_pro/flutter_app_lock_pro.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await AppLock.enable(
    const AppLockConfig(
      pin: '1234',
      autoLockAfter: Duration(minutes: 2),
      maxAttempts: 5,
      blockDuration: Duration(minutes: 5),
      unlockMethods: [UnlockMethod.pin, UnlockMethod.biometric],
      secureScreen: true,
      backgroundBlur: true,
      protectedRoutes: ['/wallet', '/profile', '/settings'],
    ),
  );
  runApp(MyApp());
}

2. Wrap your app with AppLockScope

MaterialApp(
  home: AppLockScope(
    lockTitle: 'Unlock App',
    biometricReason: 'Unlock to continue',
    child: YourHomePage(),
  ),
);

Or use with named routes so the current route is detected:

MaterialApp(
  initialRoute: '/',
  onGenerateRoute: (settings) {
    return MaterialPageRoute(
      settings: settings,
      builder: (context) => AppLockScope(
        child: buildPage(settings.name),
      ),
    );
  },
);

3. Protect specific routes

Protected routes are set in AppLockConfig.protectedRoutes. When the user navigates to any of these routes (or returns from background), the lock screen is shown until they enter the correct PIN or use biometrics.

AppLock.protectRoute('/wallet');
AppLock.protectRoutes(['/wallet', '/profile', '/settings']);

4. Lock / unlock API

AppLock.lockNow();           // Lock immediately
AppLock.unlock();            // Programmatic unlock
bool locked = AppLock.isLocked;

5. Activity and auto-lock

Call AppLock.activity() on user interaction (e.g. tap, scroll) to reset the auto-lock timer:

GestureDetector(
  onTap: () {
    AppLock.activity();
    // ...
  },
  child: ...,
)

6. Wrong-attempt protection

await AppLock.enable(
  AppLockConfig(
    maxAttempts: 5,
    blockDuration: Duration(minutes: 5),
    // ...
  ),
);

bool blocked = await AppLock.isBlocked();
Duration? remaining = await AppLock.blockRemaining();

7. Screenshot and background blur

await AppLock.secureScreen(true);       // Disable screenshots/recording
await AppLock.enableBackgroundBlur(true); // Blur in app switcher

Use cases

  • Banking apps – Lock balance, transactions, and settings.
  • Crypto wallets – Lock wallet and send screens.
  • Password managers – Lock vault and sensitive views.
  • Fintech – Comply with security expectations (screenshot off, blur, auto-lock).

Example

See the example/ app for a full demo with protected routes and lock screen.

cd example && flutter run

License

See LICENSE.