Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter screen lock

this flutter plugin provides an feature for screen lock. enter your passcode to unlock the screen. you can also use biometric authentication as an option.

⚠attention

a detailed api description will be provided later.
only tentatively necessary information is provided.

features

  • by the length of the character count
  • you can change cancel and delete widget
  • optimizes the ui for device size and orientation
  • you can disable cancellation
  • you can use biometrics (local_auth plugin)
  • biometrics can be displayed on first launch
  • unlocked callback
  • you can specify a mismatch event.
  • limit the maximum number of retries

usage

you can easily lock the screen with the following code.
to unlock, enter correctstring.

simple

if you give the same input as correctstring, it will automatically close the screen.

import 'package:flutter_screen_lock/functions.dart';

screenlock(
  context: context,
  correctstring: '1234',
);

change digits

provides a screen lock that cannot be canceled.

import 'package:flutter_screen_lock/functions.dart';

screenlock(
  context: context,
  correctstring: '1234',
  cancancel: false,
);

confirmation screen

you can display the confirmation screen and get the first input with didconfirmed if the first and second inputs match.

import 'package:flutter_screen_lock/functions.dart';

screenlock(
  context: context,
  correctstring: '',
  confirmation: true,
  didconfirmed: (matchedtext) {
    print(matchedtext);
  },
);

control the confirmation state

import 'package:flutter_screen_lock/functions.dart';
import 'package:flutter_screen_lock/input_controller.dart';

final inputcontroller = inputcontroller();

screenlock(
  context: context,
  correctstring: '',
  confirmation: true,
  inputcontroller: inputcontroller,
);

// release the confirmation state at any event.
inputcontroller.unsetconfirmed();

use local_auth

add the local_auth package to pubspec.yml.

https://pub.dev/packages/local_auth

it includes an example that calls biometrics as soon as screenlock is displayed in didopened.

import 'package:flutter_screen_lock/functions.dart';
import 'package:local_auth/local_auth.dart';
import 'package:flutter/material.dart';

/// method extraction to call by initial display and custom buttons.
future<void> localauth(buildcontext context) async {
  final localauth = localauthentication();
  final didauthenticate = await localauth.authenticatewithbiometrics(
      localizedreason: 'please authenticate');
  if (didauthenticate) {
    navigator.pop(context);
  }
}

screenlock(
  context: context,
  correctstring: '1234',
  customizedbuttonchild: icon(
    icons.fingerprint,
  ),
  customizedbuttontap: () async {
    await localauth(context);
  },
  didopened: () async {
    await localauth(context);
  },
);

full customize

import 'package:flutter/material.dart';
import 'package:flutter_screen_lock/configurations/input_button_config.dart';
import 'package:flutter_screen_lock/configurations/screen_lock_config.dart';
import 'package:flutter_screen_lock/configurations/secret_config.dart';
import 'package:flutter_screen_lock/configurations/secrets_config.dart';
import 'package:flutter_screen_lock/functions.dart';
import 'package:flutter_screen_lock/screen_lock.dart';

screenlock(
  context: context,
  title: text('change title'),
  confirmtitle: text('change confirm title'),
  correctstring: '1234',
  confirmation: true,
  screenlockconfig: screenlockconfig(
    backgroundcolor: colors.deeporange,
  ),
  secretsconfig: secretsconfig(
    spacing: 15, // or spacingratio
    padding: const edgeinsets.all(40),
    secretconfig: secretconfig(
      bordercolor: colors.amber,
      bordersize: 2.0,
      disabledcolor: colors.black,
      enabledcolor: colors.amber,
      height: 15,
      width: 15,
      build: (context, {config, enabled}) {
        return sizedbox(
          child: container(
            decoration: boxdecoration(
              shape: boxshape.rectangle,
              color: enabled
                  ? config.enabledcolor
                  : config.disabledcolor,
              border: border.all(
                width: config.bordersize,
                color: config.bordercolor,
              ),
            ),
            padding: edgeinsets.all(10),
            width: config.width,
            height: config.height,
          ),
          width: config.width,
          height: config.height,
        );
      },
    ),
  ),
  inputbuttonconfig: inputbuttonconfig(
    textstyle:
        inputbuttonconfig.getdefaulttextstyle(context).copywith(
      color: colors.orange,
      fontweight: fontweight.bold,
    ),
    buttonstyle: outlinedbutton.stylefrom(
      shape: roundedrectangleborder(),
      backgroundcolor: colors.deeporange,
    ),
  ),
  cancelbutton: const icon(icons.close),
  deletebutton: const icon(icons.delete),
);


api references

screenlock / screenlock api

property type default description
context buildcontext (required) [screenlock] only
correctstring string (required) input correct string
if [confirmation] is true, it will be ignored, so set it to any string or empty.
screenlockconfig screenlockconfig screenlockconfig() refer to the api of screenlockconfig
secretsconfig secretsconfig secretsconfig() refer to the api of secretsconfig
inputbuttonconfig inputbuttonconfig inputbuttonconfig() refer to the api of inputbuttonconfig
cancancel bool true true is show cancel button. (default: true)
confirmation bool make sure the first and second inputs are the same.
digits int set the maximum number of characters to enter when [confirmation] is true.
maxretries int 0 0 is unlimited.
for example, if it is set to 1, didmaxretries will be called on the first failure.
didunlocked void function() called if the value matches the correctstring.
diderror void function(int retries) called if the value does not match the correctstring.
didmaxretries void function(int retries) events that have reached the maximum number of attempts.
didopened void function() for example, when you want to perform biometric authentication. [screenlock] only
didconfirmed void function(string matchedtext) called when the first and second inputs match during confirmation.
it is possible to receive the matched text as an argument.
customizedbuttontap future<void> function() tapped for left side lower button.
customizedbuttonchild widget child for bottom left side button.
footer widget add a widget to the footer.
cancelbutton widget change the child widget for the cancel button.
deletebutton widget change the child widget for the delete button.
title widget headingtitle(text: ‘please enter passcode.’) change the title widget.
confirmtitle widget headingtitle(text: ‘please enter confirm passcode.’) change the confirm title widget.
inputcontroller inputcontroller control the confirmation state change on the outside.

screenlockconfig api

property type default description
backgroundcolor color specifies the background color of the screen. by default, themedata will be set.
themedata themedata screenlockconfig.defaultthemedata

secretsconfig api

property type default description
spacing double absolute space between secret widgets.
if specified together with spacingratio, this will take precedence.
spacingratio double 0.05 space ratio between secret widgets.
padding edgeinsetsgeometry edgeinsets.only(top: 20, bottom: 50) padding of secrets widget.
secretconfig secretconfig secretconfig() refer to the api of secretconfig

secretconfig api

property type default description
width double 16 widget width.
height double 16 widget height.
bordersize double 1.0 border size.
bordercolor color color(0xffffffff) border color.
enabledcolor color color(0xffffffff) fill color when input is active.
disabledcolor color color(0xffffffff) fill color for unentered.

inputbuttonconfig api

property type default description
height double mediaquery.of(context).size.height * 0.6 * 0.16 button height.
width double mediaquery.of(context).size.width * 0.22 button width.
autosize bool true automatically adjust the size of the square to fit the orientation of the device.
inputstrings list<string> [‘0′,’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9’] a string to be matched against correctstring.
displaystrings list<string> [‘0′,’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9’] the string to be displayed on the screen.
style buttonstyle it is recommended that you use [outlinedbutton.stylefrom()] to change it.
textstyle textstyle changes the text style of the button.

apps i use

timekey

ios

android


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.