flutter_app_lock 1.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

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 login has occured.

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

Getting Started #

In your flutter project add the dependency:

dependencies:
  ...
  flutter_app_lock: ^1.2.0

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

Usage example #

void main() {
  runApp(AppLock(
    builder: (args) => MyApp(data: args),
    lockScreen: LockScreen(),
  ));
}

Simply wrap the initialization of MyApp (or your equivalent) in a function and pass it to the builder property of an AppLock widget.

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 instantiate your MyApp (or your equivalent) if it's an app launch or simply returns to the current running instance of your app if it's resuming.

Enabling and disabling #

It is possible to enable and disable the lockScreen on app launch and on-demand.

runApp(AppLock(
  builder: (args) => MyApp(data: args),
  lockScreen: LockScreen(),
  enabled: false,
));

The above will cause MyApp to be built instantly and lockScreen will never be shown. The default for enabled is true.

You can then enable lockScreen later on by doing:

AppLock.of(context).enable();

This will now cause the lockScreen to be shown on app pauses.

If you wanted to disable the lockScreen 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 lockScreen and then inject them in to your MyApp or equivalent, 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:

...
runApp(AppLock(
  builder: (args) => MyApp(database: args), // args is the `database` object passed in to `didUnlock`
  lockScreen: LockScreen(),
));

1.2.0 - 21st Dec 2019 #

New functionality to enable or disable the lockScreen at launch and on-demand.

runApp(AppLock(
  builder: ...,
  lockScreen: ...,
  enabled: false,
));
AppLock.of(context).enable();
AppLock.of(context).disable();

1.1.0+2 - 21st Dec 2019 #

  • Removing deprecating child method in preference for the builder method.
  • Updating Flutter version constraints

1.1.0+1 - 15th Dec 2019 #

Deprecating child method in preference for the builder method - simply a name change.

1.1.0 - 15th Dec 2019 #

Breaking change

An argument can now be passed in to the AppLock method didUnlock and is accessible through the builder method, child - this should be considered a breaking change as the builder method, child requires a parameter even if null is passed in to didUnlock.

1.0.0 - 15th Dec 2019 #

Initial release

Use AppLock to provide lock screen functionality to you Flutter apps.

example/README.md

flutter_app_lock_example #

void main() {
  runApp(AppLock(
    builder: (args) => MyApp(
      data: args,
    ),
    lockScreen: LockScreen(),
    enabled: false,
  ));
}
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        children: <Widget>[
          RaisedButton(
            child: Text('Set app lock enabled'),
            onPressed: () => AppLock.of(context).enable(),
          ),
          RaisedButton(
            child: Text('Set app lock disabled'),
            onPressed: () => AppLock.of(context).disable(),
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_app_lock: ^1.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_app_lock/flutter_app_lock.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test