Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/src/configurations/key_pad_button_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ class KeyPadButtonConfig {
);
if (buttonStyle != null) {
return buttonStyle!.copyWith(
textStyle: composed.textStyle,
textStyle: WidgetStateProperty.resolveWith((Set<WidgetState> states) {
final TextStyle? composedTextStyle =
composed.textStyle?.resolve(states);
final TextStyle? buttonTextStyle =
buttonStyle?.textStyle?.resolve(states);

// If buttonTextStyle is null, and composedTextStyle is not null, use composedTextStyle.
// If buttonTextStyle is not null, merge it with composedTextStyle.
// If both are null, the result will be null.
return buttonTextStyle?.merge(composedTextStyle) ?? composedTextStyle;
}),
foregroundColor: composed.foregroundColor,
backgroundColor: composed.backgroundColor,
);
Expand Down
39 changes: 30 additions & 9 deletions lib/src/screen_lock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ScreenLock extends StatefulWidget {
this.secretsBuilder,
this.useBlur = true,
this.useLandscape = true,
this.backgroundBuilder,
}) : title = title ?? const Text('Please enter passcode.'),
confirmTitle = null,
digits = correctString.length,
Expand Down Expand Up @@ -69,6 +70,7 @@ class ScreenLock extends StatefulWidget {
this.secretsBuilder,
this.useBlur = true,
this.useLandscape = true,
this.backgroundBuilder,
}) : correctString = null,
title = title ?? const Text('Please enter new passcode.'),
confirmTitle =
Expand Down Expand Up @@ -158,6 +160,9 @@ class ScreenLock extends StatefulWidget {
/// Custom secrets animation widget builder.
final SecretsBuilderCallback? secretsBuilder;

/// Custom background widget builder.
final BackgroundBuilderCallback? backgroundBuilder;

/// Blur the background.
final bool useBlur;

Expand Down Expand Up @@ -353,7 +358,6 @@ class _ScreenLockState extends State<ScreenLock> {
return KeyEventResult.ignored; // Let other handlers process the event
}


Widget buildDelayChild(Duration duration) {
if (widget.delayBuilder != null) {
return widget.delayBuilder!(context, duration);
Expand Down Expand Up @@ -515,14 +519,25 @@ class _ScreenLockState extends State<ScreenLock> {
return Theme(
data: (widget.config ?? ScreenLockConfig.defaultConfig).toThemeData(),
child: Scaffold(
body: SafeArea(
child: Focus(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: _onKeyEvent,
child: buildContentWithBlur(useBlur: widget.useBlur),
),
),
body: widget.backgroundBuilder != null
? widget.backgroundBuilder!(
context: context,
child: SafeArea(
child: Focus(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: _onKeyEvent,
child: buildContentWithBlur(useBlur: widget.useBlur),
),
))
: SafeArea(
child: Focus(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: _onKeyEvent,
child: buildContentWithBlur(useBlur: widget.useBlur),
),
),
),
);
}
Expand All @@ -539,6 +554,12 @@ typedef SecretsBuilderCallback = Widget Function(
Stream<bool> verifyStream,
);

typedef BackgroundBuilderCallback = Widget Function(
{required BuildContext context, required Widget child});

BackgroundBuilderCallback defaultBackgroundBuilder =
({required BuildContext context, required Widget child}) => child;

typedef ValidationCallback = Future<bool> Function(
String input,
);