2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-09-26 15:49:36 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2022-09-26 15:49:36 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
|
|
|
import 'package:stackwallet/widgets/desktop/custom_text_button.dart';
|
|
|
|
|
2022-11-17 17:46:44 +00:00
|
|
|
export 'package:stackwallet/widgets/desktop/custom_text_button.dart';
|
|
|
|
|
2022-09-26 15:49:36 +00:00
|
|
|
class SecondaryButton extends StatelessWidget {
|
|
|
|
const SecondaryButton({
|
|
|
|
Key? key,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
this.label,
|
|
|
|
this.icon,
|
2023-03-14 22:27:34 +00:00
|
|
|
this.trailingIcon,
|
2022-09-26 15:49:36 +00:00
|
|
|
this.onPressed,
|
|
|
|
this.enabled = true,
|
2022-11-17 17:46:44 +00:00
|
|
|
this.buttonHeight,
|
2022-12-21 16:17:53 +00:00
|
|
|
this.iconSpacing = 10,
|
2023-04-03 23:00:08 +00:00
|
|
|
this.padding = EdgeInsets.zero,
|
2022-09-26 15:49:36 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final double? width;
|
|
|
|
final double? height;
|
|
|
|
final String? label;
|
|
|
|
final VoidCallback? onPressed;
|
|
|
|
final bool enabled;
|
|
|
|
final Widget? icon;
|
2023-03-14 22:27:34 +00:00
|
|
|
final Widget? trailingIcon;
|
2022-11-17 17:46:44 +00:00
|
|
|
final ButtonHeight? buttonHeight;
|
2022-12-21 16:17:53 +00:00
|
|
|
final double iconSpacing;
|
2023-04-03 23:00:08 +00:00
|
|
|
final EdgeInsets padding;
|
2022-10-27 17:05:23 +00:00
|
|
|
|
|
|
|
TextStyle getStyle(bool isDesktop, BuildContext context) {
|
|
|
|
if (isDesktop) {
|
2022-11-17 17:46:44 +00:00
|
|
|
if (buttonHeight == null) {
|
2022-10-27 17:05:23 +00:00
|
|
|
return enabled
|
|
|
|
? STextStyles.desktopButtonSecondaryEnabled(context)
|
|
|
|
: STextStyles.desktopButtonSecondaryDisabled(context);
|
|
|
|
}
|
2022-11-17 17:46:44 +00:00
|
|
|
switch (buttonHeight!) {
|
|
|
|
case ButtonHeight.xxs:
|
|
|
|
case ButtonHeight.xs:
|
|
|
|
case ButtonHeight.s:
|
|
|
|
return STextStyles.desktopTextExtraExtraSmall(context).copyWith(
|
|
|
|
color: enabled
|
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondary
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondaryDisabled,
|
|
|
|
);
|
|
|
|
|
|
|
|
case ButtonHeight.m:
|
|
|
|
case ButtonHeight.l:
|
|
|
|
return STextStyles.desktopTextExtraSmall(context).copyWith(
|
|
|
|
color: enabled
|
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondary
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondaryDisabled,
|
|
|
|
);
|
|
|
|
|
|
|
|
case ButtonHeight.xl:
|
|
|
|
case ButtonHeight.xxl:
|
|
|
|
return enabled
|
|
|
|
? STextStyles.desktopButtonSecondaryEnabled(context)
|
|
|
|
: STextStyles.desktopButtonSecondaryDisabled(context);
|
|
|
|
}
|
2022-10-27 17:05:23 +00:00
|
|
|
} else {
|
2022-12-21 16:17:53 +00:00
|
|
|
if (buttonHeight == ButtonHeight.l) {
|
|
|
|
return STextStyles.button(context).copyWith(
|
|
|
|
fontSize: 10,
|
|
|
|
color: enabled
|
|
|
|
? Theme.of(context).extension<StackColors>()!.buttonTextSecondary
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondaryDisabled,
|
|
|
|
);
|
|
|
|
}
|
2023-02-01 21:02:41 +00:00
|
|
|
if (buttonHeight == ButtonHeight.xl) {
|
|
|
|
return STextStyles.button(context).copyWith(
|
|
|
|
fontSize: 14,
|
|
|
|
color: enabled
|
|
|
|
? Theme.of(context).extension<StackColors>()!.buttonTextSecondary
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondaryDisabled,
|
|
|
|
);
|
|
|
|
}
|
2022-10-27 17:05:23 +00:00
|
|
|
return STextStyles.button(context).copyWith(
|
|
|
|
color: enabled
|
|
|
|
? Theme.of(context).extension<StackColors>()!.buttonTextSecondary
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.buttonTextSecondaryDisabled,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-09-26 15:49:36 +00:00
|
|
|
|
2022-11-17 17:46:44 +00:00
|
|
|
double? _getHeight() {
|
|
|
|
if (buttonHeight == null) {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Util.isDesktop) {
|
|
|
|
switch (buttonHeight!) {
|
|
|
|
case ButtonHeight.xxs:
|
|
|
|
return 32;
|
2022-11-17 18:01:52 +00:00
|
|
|
case ButtonHeight.xs:
|
|
|
|
return 37;
|
2022-11-17 17:46:44 +00:00
|
|
|
case ButtonHeight.s:
|
|
|
|
return 40;
|
|
|
|
case ButtonHeight.m:
|
|
|
|
return 48;
|
|
|
|
case ButtonHeight.l:
|
|
|
|
return 56;
|
|
|
|
case ButtonHeight.xl:
|
|
|
|
return 70;
|
|
|
|
case ButtonHeight.xxl:
|
|
|
|
return 96;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (buttonHeight!) {
|
|
|
|
case ButtonHeight.xxs:
|
|
|
|
case ButtonHeight.xs:
|
|
|
|
case ButtonHeight.s:
|
|
|
|
case ButtonHeight.m:
|
|
|
|
return 28;
|
|
|
|
case ButtonHeight.l:
|
|
|
|
return 30;
|
|
|
|
case ButtonHeight.xl:
|
|
|
|
return 46;
|
|
|
|
case ButtonHeight.xxl:
|
|
|
|
return 56;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 15:49:36 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final isDesktop = Util.isDesktop;
|
|
|
|
|
|
|
|
return CustomTextButtonBase(
|
2022-11-17 17:46:44 +00:00
|
|
|
height: _getHeight(),
|
2022-09-26 15:49:36 +00:00
|
|
|
width: width,
|
|
|
|
textButton: TextButton(
|
|
|
|
onPressed: enabled ? onPressed : null,
|
|
|
|
style: enabled
|
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2023-01-24 19:29:12 +00:00
|
|
|
.getSecondaryEnabledButtonStyle(context)
|
2022-09-26 15:49:36 +00:00
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2023-01-24 19:29:12 +00:00
|
|
|
.getSecondaryDisabledButtonStyle(context),
|
2023-04-03 23:00:08 +00:00
|
|
|
child: Padding(
|
|
|
|
padding: padding,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
if (icon != null) icon!,
|
|
|
|
if (icon != null && label != null)
|
|
|
|
SizedBox(
|
|
|
|
width: iconSpacing,
|
|
|
|
),
|
|
|
|
if (label != null)
|
|
|
|
Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
label!,
|
|
|
|
style: getStyle(isDesktop, context),
|
2023-01-09 19:15:15 +00:00
|
|
|
),
|
2023-04-03 23:00:08 +00:00
|
|
|
if (buttonHeight != null && buttonHeight == ButtonHeight.s)
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (trailingIcon != null)
|
|
|
|
SizedBox(
|
|
|
|
width: iconSpacing,
|
|
|
|
),
|
|
|
|
if (trailingIcon != null) trailingIcon!,
|
|
|
|
],
|
|
|
|
),
|
2022-09-26 15:49:36 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|