Skip to content

Commit

Permalink
Fix size Discard Changes button in dialog composer
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed May 24, 2024
1 parent c705bac commit 493d9f9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 21 deletions.
71 changes: 53 additions & 18 deletions core/lib/presentation/views/dialog/confirmation_dialog_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ConfirmDialogBuilder {
Color? _backgroundColor;
bool showAsBottomSheet;
List<TextSpan>? listTextSpan;
int? titleActionButtonMaxLines;
bool isArrangeActionButtonsVertical;

OnConfirmButtonAction? _onConfirmButtonAction;
OnCancelButtonAction? _onCancelButtonAction;
Expand All @@ -45,6 +47,8 @@ class ConfirmDialogBuilder {
this.showAsBottomSheet = false,
this.listTextSpan,
this.maxWith = double.infinity,
this.titleActionButtonMaxLines,
this.isArrangeActionButtonsVertical = false,
}
);

Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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
)),
),
);
}
}
20 changes: 17 additions & 3 deletions lib/features/base/mixin/message_dialog_action_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,21 @@ mixin MessageDialogActionMixin {
Color? cancelButtonColor,
EdgeInsetsGeometry? marginIcon,
PopInvokedCallback? onPopInvoked,
bool isArrangeActionButtonsVertical = false,
int? titleActionButtonMaxLines,
}
) async {
final responsiveUtils = Get.find<ResponsiveUtils>();
final imagePaths = Get.find<ImagePaths>();

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)
Expand Down Expand Up @@ -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 ?? '')
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: () {
Expand Down

0 comments on commit 493d9f9

Please sign in to comment.