패키지, 저장소 및 앱 카테고리 검색

패키지 상세v4.3.0

flutter_app_lock

앱 열기 및 앱 일시정지 시 잠금 화면을 표시하기 위한 Flutter 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
2.2천
좋아요
125
Pub 점수
150

패키지 설치

flutter pub add flutter_app_lock

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Flutter App Lock는 앱이 시작되거나 일시 중지될 때 잠금 화면 인터페이스를 구현할 수 있도록 해주는 Flutter 패키지입니다. 생체 인식 인증(지문 또는 얼굴 인식 등) 또는 사용자 정의 PIN/비밀번호를 통해 앱 접근을 간편하게 보호할 수 있습니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 여러 플랫폼을 지원하여 사용자 인증이 필요한 크로스플랫폼 애플리케이션에 적합합니다. Flutter의 위젯 시스템과 원활하게 통합되며 잠금 화면 UI 및 동작을 사용자 정의할 수 있습니다.

사용 사례

  • 시작 시 민감한 앱 데이터 보호
  • 앱 일시 정지 후 재인증 필요
  • 공유 장치에서 개인 정보 보호
  • 기업 앱에서 접근 제어 강제 적용
  • 금융 또는 건강 앱에 보안 레이어 추가

주요 기능

  • 생체 인증 지원
  • 사용자 정의 가능한 잠금 화면 UI
  • 크로스 플랫폼 호환성
  • 기존 Flutter 앱과의 간편한 통합
  • 사용자 정의 가능한 타임아웃 및 재잠금 동작

적합한 대상

  • 보안 모바일 또는 데스크톱 앱을 개발하는 개발자
  • 사용자 개인 정보 데이터를 처리하는 앱
  • 기업 또는 정부용 애플리케이션
  • 데이터 보호 기준 준수를 요구하는 앱

고려 사항

  • 생체 인식을 위한 적절한 플랫폼 권한이 필요합니다
  • 과도하게 사용할 경우 사용자 경험에 영향을 줄 수 있습니다
  • 지속적인 백그라운드 작동이 필요한 앱에는 적합하지 않습니다
  • 웹 및 데스크톱 플랫폼을 위한 추가 설정이 필요합니다
  • 신뢰성을 위해 하위 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.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트