naoki0719 / flutter_screen_lock

Provides the ability to lock the screen on ios and android. Biometric authentication can be used in addition to passcode.
https://pub.dev/packages/flutter_screen_lock
MIT License
99 stars 46 forks source link

Is this package suitable for processing the passcode on the server? #115

Closed Reyth3 closed 1 week ago

Reyth3 commented 4 months ago

Hi, I saw in the examples that with this package you have to provide correctString parameter. Can I skip it if I do not know the correct password ahead of time and will only know if it was correct or not after I get the response from the server?

For my use case, the ideal behavior would be exactly like screenLockCreate, but without the password confirm, and with a success callback with value param. Is this doable?

Thank you!

naoki0719 commented 4 months ago

@Reyth3

See the same example below. https://github.com/naoki0719/flutter_screen_lock/blob/f22571640a2b1f038db3cf185bdf18d263e7e7fb/example/lib/main.dart#L288-L298

ElevatedButton(
  onPressed: () => screenLock(
    context: context,
    correctString: 'x' * 5,
    onValidate: (value) async => await Future<bool>.delayed(
      const Duration(milliseconds: 500),
      () => value == '12345',
    ),
  ),
  child: const Text('Callback validation'),
);

The correctString should be a dummy string to set the length of the input. For example, correctString: 'x' * 5 for 5 characters. Next, define the necessary onValidate. In our example, the length is 5 characters, so this callback will be executed after 5 characters are entered. The value argument contains the input value, so you can validate it remotely or otherwise and return true to close it.