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
)),
),
);
}
}
@@ -34,6 +34,8 @@ mixin MessageDialogActionMixin {
Color? cancelButtonColor,
EdgeInsetsGeometry? marginIcon,
PopInvokedCallback? onPopInvoked,
bool isArrangeActionButtonsVertical = false,
int? titleActionButtonMaxLines,
}
) async {
final responsiveUtils = Get.find<ResponsiveUtils>();
@@ -41,7 +43,12 @@ mixin MessageDialogActionMixin {
if (alignCenter) {
final childWidget = PointerInterceptor(
child: (ConfirmDialogBuilder(imagePaths, listTextSpan: listTextSpan)
child: (ConfirmDialogBuilder(
imagePaths,
listTextSpan: listTextSpan,
titleActionButtonMaxLines: titleActionButtonMaxLines,
isArrangeActionButtonsVertical: isArrangeActionButtonsVertical
)
..key(const Key('confirm_dialog_action'))
..title(title ?? '')
..content(message)
@@ -92,7 +99,9 @@ mixin MessageDialogActionMixin {
imagePaths,
showAsBottomSheet: true,
listTextSpan: listTextSpan,
maxWith: responsiveUtils.getSizeScreenShortestSide(context) - 16
maxWith: responsiveUtils.getSizeScreenShortestSide(context) - 16,
titleActionButtonMaxLines: titleActionButtonMaxLines,
isArrangeActionButtonsVertical: isArrangeActionButtonsVertical
)
..key(const Key('confirm_dialog_action'))
..title(title ?? '')
@@ -168,7 +177,12 @@ mixin MessageDialogActionMixin {
}
} else {
final childWidget = PointerInterceptor(
child: (ConfirmDialogBuilder(imagePaths, listTextSpan: listTextSpan)
child: (ConfirmDialogBuilder(
imagePaths,
listTextSpan: listTextSpan,
titleActionButtonMaxLines: titleActionButtonMaxLines,
isArrangeActionButtonsVertical: isArrangeActionButtonsVertical
)
..key(const Key('confirm_dialog_action'))
..title(title ?? '')
..content(message)
@@ -1923,6 +1923,8 @@ class ComposerController extends BaseController with DragDropFileMixin {
alignCenter: true,
outsideDismissible: false,
autoPerformPopBack: false,
titleActionButtonMaxLines: 1,
isArrangeActionButtonsVertical: true,
usePopScope: true,
onConfirmAction: () => _handleSaveMessageToDraft(context),
onCancelAction: () {