Fix size Discard Changes button in dialog composer

This commit is contained in:
dab246
2024-05-24 16:29:30 +07:00
committed by Dat H. Pham
parent 53e231e8a4
commit 016c59e395
3 changed files with 72 additions and 21 deletions
@@ -34,6 +34,8 @@ class ConfirmDialogBuilder {
Color? _backgroundColor;
bool showAsBottomSheet;
List<TextSpan>? listTextSpan;
int? titleActionButtonMaxLines;
bool isArrangeActionButtonsVertical;
OnConfirmButtonAction? _onConfirmButtonAction;
OnCancelButtonAction? _onCancelButtonAction;
@@ -45,6 +47,8 @@ class ConfirmDialogBuilder {
this.showAsBottomSheet = false,
this.listTextSpan,
this.maxWith = double.infinity,
this.titleActionButtonMaxLines,
this.isArrangeActionButtonsVertical = false,
}
);
@@ -223,7 +227,32 @@ class ConfirmDialogBuilder {
),
),
),
Padding(
if (isArrangeActionButtonsVertical)
...[
if (_cancelText.isNotEmpty)
Padding(
padding: const EdgeInsetsDirectional.only(top: 8, start: 16, end: 16),
child: _buildButton(
name: _cancelText,
bgColor: _colorCancelButton,
radius: _radiusButton,
textStyle: _styleTextCancelButton,
action: _onCancelButtonAction),
),
if (_confirmText.isNotEmpty)
Padding(
padding: const EdgeInsetsDirectional.only(top: 8, start: 16, end: 16),
child: _buildButton(
name: _confirmText,
bgColor: _colorConfirmButton,
radius: _radiusButton,
textStyle: _styleTextConfirmButton,
action: _onConfirmButtonAction),
),
const SizedBox(height: 16),
]
else
Padding(
padding: _paddingButton ?? const EdgeInsetsDirectional.only(bottom: 16, start: 16, end: 16),
child: Row(
children: [
@@ -254,27 +283,33 @@ class ConfirmDialogBuilder {
TextStyle? textStyle,
Color? bgColor,
double? radius,
Function? action
Function()? action
}) {
return SizedBox(
width: double.infinity,
height: titleActionButtonMaxLines == 1 ? 45 : null,
child: ElevatedButton(
onPressed: () => action?.call(),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) => bgColor ?? AppColor.colorTextButton),
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) => bgColor ?? AppColor.colorTextButton),
shape: MaterialStateProperty.all(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radius ?? 8),
side: BorderSide(width: 0, color: bgColor ?? AppColor.colorTextButton),
)),
padding: MaterialStateProperty.resolveWith<EdgeInsets>((Set<MaterialState> states) => const EdgeInsets.all(8)),
elevation: MaterialStateProperty.resolveWith<double>((Set<MaterialState> states) => 0)),
child: Text(name ?? '',
textAlign: TextAlign.center,
style: textStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white)),
)
onPressed: action,
style: ElevatedButton.styleFrom(
foregroundColor: bgColor ?? AppColor.colorTextButton,
backgroundColor: bgColor ?? AppColor.colorTextButton,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radius ?? 8),
side: BorderSide(width: 0, color: bgColor ?? AppColor.colorTextButton),
),
padding: const EdgeInsets.all(8),
elevation: 0
),
child: Text(
name ?? '',
textAlign: TextAlign.center,
maxLines: titleActionButtonMaxLines,
style: textStyle ?? const TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Colors.white
)),
),
);
}
}