stack_wallet/lib/widgets/stack_dialog.dart

214 lines
5.6 KiB
Dart
Raw Normal View History

2022-08-26 08:11:35 +00:00
import 'package:flutter/material.dart';
import 'package:stackwallet/themes/stack_colors.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/text_styles.dart';
2022-11-09 22:32:39 +00:00
import 'package:stackwallet/utilities/util.dart';
2022-08-26 08:11:35 +00:00
class StackDialogBase extends StatelessWidget {
const StackDialogBase({
Key? key,
this.child,
this.padding = const EdgeInsets.all(24),
}) : super(key: key);
final EdgeInsets padding;
final Widget? child;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Column(
2022-11-09 22:32:39 +00:00
mainAxisAlignment:
!Util.isDesktop ? MainAxisAlignment.end : MainAxisAlignment.center,
2022-08-26 08:11:35 +00:00
children: [
2023-03-09 16:12:47 +00:00
Flexible(
child: SingleChildScrollView(
child: Material(
2022-08-26 08:11:35 +00:00
borderRadius: BorderRadius.circular(
20,
),
2023-03-09 16:12:47 +00:00
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).extension<StackColors>()!.popupBG,
borderRadius: BorderRadius.circular(
20,
),
),
child: Padding(
padding: padding,
child: child,
),
),
2022-08-26 08:11:35 +00:00
),
),
),
],
),
);
}
}
class StackDialog extends StatelessWidget {
const StackDialog({
Key? key,
this.leftButton,
this.rightButton,
this.icon,
required this.title,
this.message,
}) : super(key: key);
final Widget? leftButton;
final Widget? rightButton;
final Widget? icon;
final String title;
final String? message;
@override
Widget build(BuildContext context) {
return StackDialogBase(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
title,
2022-09-22 22:17:21 +00:00
style: STextStyles.pageTitleH2(context),
2022-08-26 08:11:35 +00:00
),
),
icon != null ? icon! : Container(),
],
),
if (message != null)
const SizedBox(
height: 8,
),
if (message != null)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
message!,
2022-09-22 22:17:21 +00:00
style: STextStyles.smallMed14(context),
2022-08-26 08:11:35 +00:00
),
],
),
if (leftButton != null || rightButton != null)
const SizedBox(
height: 20,
),
if (leftButton != null || rightButton != null)
Row(
children: [
leftButton == null
? const Spacer()
: Expanded(child: leftButton!),
const SizedBox(
width: 8,
),
rightButton == null
? const Spacer()
: Expanded(child: rightButton!),
],
)
],
),
);
}
}
class StackOkDialog extends StatelessWidget {
const StackOkDialog({
Key? key,
this.leftButton,
this.onOkPressed,
this.icon,
required this.title,
this.message,
}) : super(key: key);
final Widget? leftButton;
final void Function(String)? onOkPressed;
final Widget? icon;
final String title;
final String? message;
@override
Widget build(BuildContext context) {
return StackDialogBase(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
title,
2022-09-22 22:17:21 +00:00
style: STextStyles.pageTitleH2(context),
2022-08-26 08:11:35 +00:00
),
),
icon != null ? icon! : Container(),
],
),
if (message != null)
const SizedBox(
height: 8,
),
if (message != null)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
message!,
2022-09-22 22:17:21 +00:00
style: STextStyles.smallMed14(context),
2022-08-26 08:11:35 +00:00
),
],
),
const SizedBox(
height: 20,
),
Row(
children: [
leftButton == null
? const Spacer()
: Expanded(child: leftButton!),
const SizedBox(
width: 8,
),
Expanded(
child: TextButton(
2022-11-09 22:32:39 +00:00
onPressed: !Util.isDesktop
? () {
Navigator.of(context).pop();
onOkPressed?.call("OK");
}
: () {
int count = 0;
Navigator.of(context).popUntil((_) => count++ >= 2);
// onOkPressed?.call("OK");
},
style: Theme.of(context)
.extension<StackColors>()!
2023-01-24 19:29:12 +00:00
.getPrimaryEnabledButtonStyle(context),
2022-08-26 08:11:35 +00:00
child: Text(
"Ok",
2022-09-22 22:17:21 +00:00
style: STextStyles.button(context),
2022-08-26 08:11:35 +00:00
),
),
),
],
)
],
),
);
}
}