搜尋套件、儲存庫與 APP 分類

套件詳情v4.3.0

flutter_app_lock

一個用於在應用程式開啟和暫停時顯示鎖定畫面的 Flutter 套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2240
喜歡數
125
Pub 分數
150

安裝套件

flutter pub add flutter_app_lock

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Flutter App Lock 是一個 Flutter 套件,可在應用程式啟動或暫停時啟用鎖屏介面。它提供了一種簡單的方法,透過生物識別認證(如指紋或臉部辨識)或自訂 PIN/密碼來保護應用程式存取。此套件支援 Android、iOS、Web、macOS、Windows 和 Linux 等多個平台,非常適合需要使用者驗證的跨平台應用程式。它與 Flutter 的 widget 系統無縫整合,並允許自訂鎖屏 UI 與行為。

適用情境

  • 在啟動時保護敏感的應用程式資料
  • 應用暫停後需要重新進行身分驗證
  • 保護共享設備中的個人信息
  • 在企業應用中強制執行存取控制
  • 為金融或健康應用添加安全層

主要特色

  • 生物識別認證支援
  • 可自定義的鎖屏UI
  • 跨平台相容性
  • 與現有 Flutter 應用輕鬆整合
  • 可設定的逾時和重新鎖定行為

適合對象

  • 開發安全的移動或桌面應用程式的開發者
  • 處理使用者隱私資料的應用程式
  • 企業或政府應用程式
  • 需要符合資料保護標準的應用程式

使用建議

  • 需要適當的平台權限以使用生物識別功能
  • 如果過度使用,可能會影響使用者體驗
  • 不適用於需要連續背景運作的應用程式
  • Web 和桌面平台需要額外設置
  • 依賴底層作業系統生物識別服務以確保可靠性

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_app_lock

A Flutter package for showing a lock screen on app open and app pause.

If the app is launching, the lock screen is shown first and then the rest of the app is instantiated once a successful unlock has occured.

If the user is returning to the app after it has already launched, the lock screen is shown on top of your app and can't be dismissed until another successful unlock.

Getting Started

In your flutter project add the dependency:

dependencies:
  ...
  flutter_app_lock: ^4.2.0+2

For help getting started with Flutter, view the online documentation.

Usage example

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  ...

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      ...,
      builder: (context, child) => AppLock(
        builder: (context, arg) => child!,
        lockScreenBuilder: (context) => LockScreen(),
      ),
    );
  }
}

Simply use your MaterialApp's builder property to return an AppLock widget, passing child to its own builder property.

Note: While I mention MaterialApp throughout this README, this is also compatible with CupertinoApp and WidgetsApp widgets.

LockScreen is your own widget implementing your own login logic which should call the following once a successful login has occured.

AppLock.of(context)!.didUnlock();

This will now make the MaterialApp's Navigator or Router the top most widget.

Theme

Because AppLock is expected to be returned within your MaterialApp's builder method, your existing theme and theme variants will style the widget returned from lockScreenBuilder automatically.

MaterialApp(
  ...,
  theme: ThemeData(
    ...,
  ),
  builder: (context, child) => AppLock(
    builder: (context, arg) => child!,
    lockScreenBuilder: (context) => LockScreen(),
  ),
);

Enabling and disabling

It is possible to enable and disable the showing of the widget returned from lockScreenBuilder on app launch and on-demand.

MaterialApp(
  ...,
  builder: (context, child) => AppLock(
    builder: (context, arg) => child!,
    lockScreenBuilder: (context) => LockScreen(),
    initiallyEnabled: false,
  ),
);

The above will cause child (your MaterialApp's Navigator or Router) to be built instantly and the widget returned from lockScreenBuilder will never be shown. The default for initiallyEnabled is true.

You can then enable the showing of the widget returned from lockScreenBuilder later on by doing:

AppLock.of(context)!.enable();

This will now cause the widget returned from lockScreenBuilder to be shown on app pauses.

If you wanted to disable the showing of the widget returned from lockScreenBuilder again you can simply do:

AppLock.of(context)!.disable();

There is also a convenience method:

AppLock.of(context)!.setEnabled(true);
AppLock.of(context)!.setEnabled(false);

Passing arguments

In some scenarios, it might be appropriate to unlock a database or create some other objects from the widget returned from lockScreenBuilder and then expose them to your app further down the tree, so you can better guarantee that services are instantiated or databases are opened/unlocked.

You can do this by passing in an argument to the didUnlock method on AppLock:

var database = await openDatabase(...);

AppLock.of(context)!.didUnlock(database);

This object is then available as part of the AppLock builder method, builder:

MaterialApp(
  ...,
  builder: (context, child) => AppLock(
    builder: (context, arg) => child!, // arg is the `database` object passed in to `didUnlock`
    lockScreenBuilder: (context) => LockScreen(),
  ),
);

It is also available by calling AppLock.of(context)!.launchArg.

Manually showing the lock screen

In some scenarios, you might want to manually trigger the lock screen to show.

You can do this by calling:

AppLock.of(context)!.showLockScreen();

If you want to wait until the user has successfully unlocked again, showLockScreen returns a Future so you can await this method call.

await AppLock.of(context)!.showLockScreen();

print('Did unlock!');

Background lock latency

It might be useful for apps to not require the lock screen to be shown immediately after entering the background state. You can now specify how long the app is allowed to be in the background before requiring the lock screen to be shown:

MaterialApp(
  ...,
  builder: (context, child) => AppLock(
    ...,
    initialBackgroundLockLatency: const Duration(seconds: 30),
  ),
);

The above example allows the app to be in the background for up to 30 seconds without requiring the lock screen to be shown.

It's also possible to change this at runtime using the method:

AppLock.of(context)!.setBackgroundLockLatency(const Duration(seconds: 5));

Inactive statuses (e.g. app switcher)

When the app becomes "inactive", for example by launching the device app switcher or device notification center, you can now configure a widget to be shown when this occurs:

MaterialApp(
  ...,
  builder: (context, child) => AppLock(
    ...,
    inactiveBuilder: (context) => InactiveScreen(),
  ),
);

InactiveScreen is your own widget implementing your own requirements for a screen shown while the app is inactive.

There are limitations to this as noted on issue #6 on GitHub.

The widget returned by inactiveBuilder is only shown if AppLock is enabled (default behavior). This can be changed so the widget returned by inactiveBuilder is shown whenever the app is inactive, irrespective of whether AppLock is enabled or not, by setting inactiveBehavior to InactiveBehavior.alwaysShow.

MaterialApp(
  ...,
  builder: (context, child) => AppLock(
    ...,
    inactiveBehavior: InactiveBehavior.showWhenEnabled, // only show when the app is in active and AppLock is enabled (default)
  ),
);
MaterialApp(
  ...,
  builder: (context, child) => AppLock(
    ...,
    inactiveBehavior: InactiveBehavior.alwaysShow, // always show when the app is inactive
  ),
);

Tests

Integration tests have been introduced in the example project and were used to confirm the behavior hasn't changed since the move to null-safety.

They can be run by running flutter test integration_test/integration_tests.dart in a terminal.

所屬分類

原始碼儲存庫

使用此套件的專案