137 lines
4.8 KiB
Dart
137 lines
4.8 KiB
Dart
import 'package:cims_apps/application/theme/color_palette.dart';
|
|
import 'package:cims_apps/core/utils/size_config.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ButtonView extends StatelessWidget {
|
|
final String name;
|
|
final VoidCallback onPressed;
|
|
final Widget? prefixIcon, suffixIcon;
|
|
final double? height, width, widthSuffix, widthPrefix, marginVertical;
|
|
final EdgeInsetsGeometry? contentPadding;
|
|
final bool isSecondaryColor, isOutlined, heightWrapContent, disabled;
|
|
final Color? backgroundColor, textColor;
|
|
final MainAxisAlignment? mainAxisAlignmentContent;
|
|
// final _widthBtn = SizeConfig.screenWidth / 1.5;
|
|
final _widthBtn = SizeConfig.width * .9;
|
|
// final _heightBtn = SizeConfig.screenHeight / 12;
|
|
final _heightBtn = SizeConfig.height * .07;
|
|
final FontWeight textWeight;
|
|
final double? textSize, sizeBorderRadius;
|
|
final int? maxLines;
|
|
|
|
ButtonView(
|
|
{super.key,
|
|
required this.name,
|
|
required this.onPressed,
|
|
this.prefixIcon,
|
|
this.suffixIcon,
|
|
this.widthPrefix,
|
|
this.widthSuffix,
|
|
this.height,
|
|
this.width,
|
|
this.contentPadding,
|
|
this.backgroundColor,
|
|
this.textColor,
|
|
this.textWeight = FontWeight.bold,
|
|
this.textSize,
|
|
this.mainAxisAlignmentContent,
|
|
this.disabled = false,
|
|
this.heightWrapContent = false,
|
|
this.isSecondaryColor = false,
|
|
this.isOutlined = false,
|
|
this.maxLines = 2,
|
|
this.sizeBorderRadius,
|
|
this.marginVertical})
|
|
: assert(
|
|
suffixIcon == null || prefixIcon == null,
|
|
"Cannot provide both a suffixIcon and a prefixIcon, select one",
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final color = Theme.of(context).colorScheme;
|
|
final widthSuffix =
|
|
this.widthSuffix ?? (heightWrapContent ? width! / 4.7 : _widthBtn / 16);
|
|
final widthPrefix =
|
|
this.widthPrefix ?? (heightWrapContent ? width! / 4.7 : _widthBtn / 16);
|
|
|
|
return Center(
|
|
child: Container(
|
|
margin: EdgeInsets.symmetric(vertical: marginVertical ?? 24.0),
|
|
width: width ?? _widthBtn,
|
|
height: heightWrapContent ? null : height ?? _heightBtn,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
disabledBackgroundColor: isOutlined ? Colors.white : color.surface,
|
|
padding: contentPadding,
|
|
backgroundColor: backgroundColor ??
|
|
(isOutlined
|
|
? Colors.white
|
|
: isSecondaryColor
|
|
? ColorPalette.grey
|
|
: ColorPalette.primary),
|
|
elevation: 0,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(sizeBorderRadius ?? 48),
|
|
side: isOutlined
|
|
? BorderSide(
|
|
color: disabled
|
|
? ColorPalette.greyBorder
|
|
: isSecondaryColor
|
|
? ColorPalette.greyBorder
|
|
: ColorPalette.primary,
|
|
)
|
|
: BorderSide.none,
|
|
),
|
|
),
|
|
onPressed: disabled ? null : onPressed,
|
|
child: Row(
|
|
mainAxisAlignment: mainAxisAlignmentContent ??
|
|
(prefixIcon != null
|
|
? MainAxisAlignment.center
|
|
: suffixIcon != null
|
|
? MainAxisAlignment.end
|
|
: MainAxisAlignment.center),
|
|
children: [
|
|
if (prefixIcon != null) ...[
|
|
prefixIcon!,
|
|
SizedBox(width: widthPrefix),
|
|
] else
|
|
Container(),
|
|
Flexible(
|
|
child: Text(
|
|
name,
|
|
textAlign: TextAlign.center,
|
|
maxLines: maxLines,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: textSize ?? 16,
|
|
fontWeight: textWeight,
|
|
color: textColor ??
|
|
(disabled && isOutlined
|
|
? color.primary
|
|
: disabled
|
|
? Colors.white
|
|
: isOutlined && isSecondaryColor
|
|
? ColorPalette.blackFont
|
|
: isOutlined
|
|
? color.primary
|
|
: isSecondaryColor
|
|
? Colors.white
|
|
: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
if (suffixIcon != null) ...[
|
|
SizedBox(width: widthSuffix),
|
|
suffixIcon!
|
|
] else
|
|
Container()
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|