Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev4.3.0

flutter_app_lock

Um pacote Flutter para exibir uma tela de bloqueio ao abrir o aplicativo e ao pausar o aplicativo.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
2,2 mil
Curtidas
125
Pontos Pub
150

Instalar pacote

flutter pub add flutter_app_lock

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

O Flutter App Lock é um pacote do Flutter que permite aos desenvolvedores implementar uma interface de tela de bloqueio quando o aplicativo é iniciado ou pausado. Ele oferece uma maneira simples de proteger o acesso ao aplicativo usando autenticação biométrica (como impressão digital ou reconhecimento facial) ou um PIN/senha personalizado. O pacote suporta múltiplas plataformas, incluindo Android, iOS, Web, macOS, Windows e Linux, tornando-o ideal para aplicações multiplataforma que exigem autenticação de usuário. Integra-se perfeitamente com o sistema de widgets do Flutter e permite a personalização da interface e do comportamento da tela de bloqueio.

Casos de uso

  • Protegendo dados sensíveis do aplicativo no lançamento
  • Requer autenticação novamente após pausa no aplicativo
  • Protegendo informações pessoais em dispositivos compartilhados
  • Imporção de controle de acesso em aplicativos corporativos
  • Adicionando camadas de segurança a aplicativos financeiros ou de saúde

Principais recursos

  • Suporte de autenticação biométrica
  • UI de tela de bloqueio personalizável
  • Compatibilidade multiplataforma
  • Integração fácil com aplicativos Flutter existentes
  • Comportamento configurável de tempo limite e bloqueio

Indicado para

  • Desenvolvedores construindo aplicativos móveis ou de desktop seguros
  • Aplicativos que lidam com dados privados do usuário
  • Aplicações corporativas ou governamentais
  • Aplicativos que exigem conformidade com padrões de proteção de dados

Considerações

  • Requer permissões apropriadas da plataforma para biometria
  • Pode afetar a experiência do usuário se usado em excesso
  • Não adequado para aplicativos que exigem operação contínua em segundo plano
  • Configuração adicional necessária para plataformas web e desktop
  • Depende dos serviços biométricos subjacentes do sistema operacional para confiabilidade

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

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.

Categorias

Repositório-fonte

Projetos que usam este pacote