Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adjustable modal size, dismiss button displayed only if canDism… #5

Merged
merged 2 commits into from
Feb 23, 2025
Merged
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
25 changes: 21 additions & 4 deletions lib/src/ui/sec_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:mtrust_sec_kit/src/ui/sec_result.dart';
/// Provide a [builder] that renders some UI with a callback to open the sheet.
class SecModalBuilder extends StatelessWidget {
/// Creates a new instance of [SecModalBuilder]
const SecModalBuilder({
const SecModalBuilder({
required this.strategy,
required this.payload,
required this.onVerificationDone,
Expand All @@ -23,6 +23,8 @@ class SecModalBuilder extends StatelessWidget {
this.disconnectOnClose = true,
this.turnOffOnClose = true,
this.canDismiss = true,
this.fixedDialogSize = const Size(400, 400),
this.tokenAmount,
super.key,
});

Expand Down Expand Up @@ -50,9 +52,15 @@ class SecModalBuilder extends StatelessWidget {
/// The builder that opens the sheet.
final Widget Function(BuildContext context, Function openSheet) builder;

/// Whether the modal can be dissmissed by the user
/// Whether the modal can be dissmissed by the user.
final bool canDismiss;

/// Size of the modal.
final Size fixedDialogSize;

/// Amount of tokens to be requested on token refresh.
final int? tokenAmount;

@override
Widget build(BuildContext context) {
var topRadius = LdTheme.of(context).sizingConfig.radiusM;
Expand Down Expand Up @@ -101,6 +109,8 @@ class SecModalBuilder extends StatelessWidget {
useSafeArea: useSafeArea,
strategy: strategy,
payload: payload,
fixedDialogSize: fixedDialogSize,
tokenAmount: tokenAmount,
),
);
}
Expand Down Expand Up @@ -146,15 +156,21 @@ LdModal secModal({

/// Whether to use safe area inside the modal
required bool useSafeArea,

/// Size of the modal
Size fixedDialogSize = const Size(400, 400),

/// Amount of token to be requested on token refresh
int? tokenAmount,
}) {
return LdModal(
disableScrolling: true,
padding: EdgeInsets.zero,
noHeader: true,
showDismissButton: false,
showDismissButton: canDismiss,
userCanDismiss: canDismiss,
topRadius: topRadius,
fixedDialogSize: const Size(400, 400),
fixedDialogSize: fixedDialogSize,
bottomRadius: bottomRadius,
useSafeArea: useSafeArea,
insets: insets,
Expand All @@ -170,6 +186,7 @@ LdModal secModal({
onVerificationFailed: () async {
Navigator.of(context).pop(SecResultFailed());
},
tokenAmount: tokenAmount,
),
).padL(),
);
Expand Down
7 changes: 7 additions & 0 deletions lib/src/ui/sec_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SecWidget extends StatelessWidget {
required this.onVerificationDone,
required this.onVerificationFailed,
this.storageAdapter,
this.tokenAmount,
super.key,
});

Expand All @@ -35,6 +36,9 @@ class SecWidget extends StatelessWidget {
/// Will be called if a verification failed.
final Future<void> Function() onVerificationFailed;

/// Amount of token to be requested on token refresh.
final int? tokenAmount;

@override
Widget build(BuildContext context) {
return DeviceConnector(
Expand All @@ -49,6 +53,9 @@ class SecWidget extends StatelessWidget {
final reader = SECReader(
connectionStrategy: strategy,
);
if(tokenAmount != null) {
reader.setTokenAmount(tokenAmount!);
}
return reader.prime(payload);
},
),
Expand Down