パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細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のウィジェットシステムとシームレスに統合され、ロック画面のUIおよび動作をカスタマイズできます。

用途

  • 起動時に機密アプリデータを保護する
  • アプリの一時停止後に再認証が必要
  • 共有デバイスにおける個人情報の保護
  • エンタープライズアプリでのアクセス制御の実施
  • 金融または健康アプリにセキュリティレイヤーを追加する

主な機能

  • バイオメトリック認証のサポート
  • カスタマイズ可能なロック画面UI
  • クロスプラットフォーム互換性
  • 既存のFlutterアプリとの簡単な統合
  • タイムアウトと再ロック動作のカスタマイズ可能

適している対象

  • セキュアなモバイルまたはデスクトップアプリを構築する開発者
  • プライベートなユーザー データを扱うアプリ
  • 企業または政府向けアプリケーション
  • データ保護基準の遵守を必要とするアプリ

注意事項

  • バイオメトリクスの適切なプラットフォーム権限が必要です
  • 過剰に使用すると、ユーザー体験に影響を与える可能性があります
  • 継続的なバックグラウンド操作を必要とするアプリには適していません
  • Webおよびデスクトッププラットフォーム用の追加設定が必要です
  • 信頼性のために下位のOSバイオメトリックサービスに依存します

元の 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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト