diff --git a/lib/src/configurations/key_pad_button_config.dart b/lib/src/configurations/key_pad_button_config.dart index b50cd69..6e7af26 100644 --- a/lib/src/configurations/key_pad_button_config.dart +++ b/lib/src/configurations/key_pad_button_config.dart @@ -38,7 +38,17 @@ class KeyPadButtonConfig { ); if (buttonStyle != null) { return buttonStyle!.copyWith( - textStyle: composed.textStyle, + textStyle: WidgetStateProperty.resolveWith((Set 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, ); diff --git a/lib/src/screen_lock.dart b/lib/src/screen_lock.dart index f59ce6f..9a68c9e 100644 --- a/lib/src/screen_lock.dart +++ b/lib/src/screen_lock.dart @@ -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, @@ -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 = @@ -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; @@ -353,7 +358,6 @@ class _ScreenLockState extends State { return KeyEventResult.ignored; // Let other handlers process the event } - Widget buildDelayChild(Duration duration) { if (widget.delayBuilder != null) { return widget.delayBuilder!(context, duration); @@ -515,14 +519,25 @@ class _ScreenLockState extends State { 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), + ), + ), ), ); } @@ -539,6 +554,12 @@ typedef SecretsBuilderCallback = Widget Function( Stream verifyStream, ); +typedef BackgroundBuilderCallback = Widget Function( + {required BuildContext context, required Widget child}); + +BackgroundBuilderCallback defaultBackgroundBuilder = + ({required BuildContext context, required Widget child}) => child; + typedef ValidationCallback = Future Function( String input, );