Skip to content

Commit

Permalink
Merge pull request #35 from naoki0719:naoki0719/issue34
Browse files Browse the repository at this point in the history
Naoki0719/issue34
  • Loading branch information
naoki0719 authored Nov 23, 2021
2 parents 35acc04 + 7bbded3 commit 25523b4
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [5.0.2] - 2021-11-23

- Added an option to specify whether to blur the background.
You can optionally disable blur to deter performance degradation on some devices. (#34)

## [5.0.1] - 2021-11-16

- There was a spelling mistake, so I corrected it to "customizedButtonTap" (#31).
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ screenLock(
| 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. |
| withBlur | bool | | Blur the background |

### ScreenLockConfig API

Expand Down
12 changes: 12 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ class _MyHomePageState extends State<MyHomePage> {
),
child: const Text('Next page with unlock'),
),
ElevatedButton(
onPressed: () => screenLock<void>(
context: context,
correctString: '1234',
withBlur: false,
screenLockConfig: ScreenLockConfig(
/// If you don't want it to be transparent, override the config
backgroundColor: Colors.black,
),
),
child: const Text('Not blur'),
),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ packages:
path: ".."
relative: true
source: path
version: "5.0.1"
version: "5.0.2"
intl:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions lib/src/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import 'package:flutter_screen_lock/src/screen_lock.dart';
/// - `title`: Change the title widget
/// - `confirmTitle`: Change the confirm title widget
/// - `inputController`: Control inputs externally
/// - `withBlur`: Blur the background
Future<T>? screenLock<T>({
required BuildContext context,
required String correctString,
Expand All @@ -54,6 +55,7 @@ Future<T>? screenLock<T>({
Widget confirmTitle =
const HeadingTitle(text: 'Please enter confirm passcode.'),
InputController? inputController,
bool withBlur = true,
}) {
Navigator.push(
context,
Expand Down Expand Up @@ -93,6 +95,7 @@ Future<T>? screenLock<T>({
title: title,
confirmTitle: confirmTitle,
inputController: inputController,
withBlur: withBlur,
);
},
transitionsBuilder: (
Expand Down
77 changes: 45 additions & 32 deletions lib/src/screen_lock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ScreenLock extends StatefulWidget {
this.cancelButton,
this.deleteButton,
this.inputController,
this.withBlur = true,
}) : assert(maxRetries > -1),
super(key: key);

Expand Down Expand Up @@ -101,6 +102,9 @@ class ScreenLock extends StatefulWidget {
/// Control inputs externally.
final InputController? inputController;

/// Blur the background
final bool withBlur;

@override
_ScreenLockState createState() => _ScreenLockState();
}
Expand Down Expand Up @@ -201,45 +205,54 @@ class _ScreenLockState extends State<ScreenLock> {
Widget build(BuildContext context) {
final secretLength =
widget.confirmation ? widget.digits : widget.correctString.length;

Widget renderContent() {
return SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
buildHeadingText(),
Secrets(
config: widget.secretsConfig,
length: secretLength,
inputStream: inputController.currentInput,
verifyStream: inputController.verifyInput,
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: KeyPad(
inputButtonConfig: widget.inputButtonConfig,
inputState: inputController,
canCancel: widget.canCancel,
customizedButtonTap: widget.customizedButtonTap,
customizedButtonChild: widget.customizedButtonChild,
deleteButton: widget.deleteButton,
cancelButton: widget.cancelButton,
),
),
widget.footer ?? Container(),
],
),
);
}

Widget renderContentWithBlur() {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3.5, sigmaY: 3.5),
child: renderContent(),
);
}

return WillPopScope(
onWillPop: () async => widget.canCancel,
child: Theme(
data: makeThemeData(),
child: Scaffold(
backgroundColor: widget.screenLockConfig.backgroundColor,
body: SafeArea(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3.5, sigmaY: 3.5),
child: SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
buildHeadingText(),
Secrets(
config: widget.secretsConfig,
length: secretLength,
inputStream: inputController.currentInput,
verifyStream: inputController.verifyInput,
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: KeyPad(
inputButtonConfig: widget.inputButtonConfig,
inputState: inputController,
canCancel: widget.canCancel,
customizedButtonTap: widget.customizedButtonTap,
customizedButtonChild: widget.customizedButtonChild,
deleteButton: widget.deleteButton,
cancelButton: widget.cancelButton,
),
),
widget.footer ?? Container(),
],
),
),
),
child: widget.withBlur ? renderContentWithBlur() : renderContent(),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_screen_lock
description: Provides the ability to lock the screen on ios and android. Biometric authentication can be used in addition to passcode.
homepage: https://github.com/naoki0719/flutter_screen_lock
version: 5.0.1
version: 5.0.2

environment:
sdk: ">=2.12.0-0 <3.0.0"
Expand Down

0 comments on commit 25523b4

Please sign in to comment.