aweSideSheet function

Future<void> aweSideSheet({
  1. required BuildContext context,
  2. required SheetPosition sheetPosition,
  3. Widget? body,
  4. Widget? footer,
  5. Widget? header,
  6. bool barrierDismissible = true,
  7. bool showBackButton = true,
  8. bool showCloseButton = true,
  9. bool showActions = true,
  10. bool showFooterDivider = true,
  11. bool showHeaderDivider = true,
  12. bool showSideDivider = true,
  13. bool safeAreaTop = true,
  14. bool safeAreaBottom = true,
  15. String confirmActionText = 'Save',
  16. String cancelActionText = 'Cancel',
  17. String? title,
  18. Duration? transitionDuration,
  19. double sheetWidth = 400,
  20. double? borderRadius,
  21. Color? backgroundColor,
  22. dynamic surfaceTintColor,
  23. dynamic textColor,
  24. dynamic iconColor,
  25. dynamic dividerColor,
  26. dynamic confirmButtonBgColor,
  27. dynamic confirmButtonTextColor,
  28. dynamic cancelButtonBgColor,
  29. dynamic cancelButtonTextColor,
  30. void onConfirm()?,
  31. void onCancel()?,
  32. void onDismiss()?,
  33. void onClose()?,
})

Implementation

Future<void> aweSideSheet({
  // required
  required BuildContext context,
  required SheetPosition sheetPosition,

  // widgets
  Widget? body,
  Widget? footer,
  Widget? header,

  // bools
  bool barrierDismissible = true,
  bool showBackButton = true,
  bool showCloseButton = true,
  bool showActions = true,
  bool showFooterDivider = true,
  bool showHeaderDivider = true,
  bool showSideDivider = true,
  bool safeAreaTop = true,
  bool safeAreaBottom = true,

  // strings
  String confirmActionText = 'Save',
  String cancelActionText = 'Cancel',
  String? title,

  // duration
  Duration? transitionDuration,

  // doubles
  double sheetWidth = 400,
  double? borderRadius,

  // Colors
  Color? backgroundColor,
  surfaceTintColor,
  textColor,
  iconColor,
  dividerColor,
  confirmButtonBgColor,
  confirmButtonTextColor,
  cancelButtonBgColor,
  cancelButtonTextColor,

  // callbacks
  void Function()? onConfirm,
  void Function()? onCancel,
  void Function()? onDismiss,
  void Function()? onClose,
}) async {
  await showGeneralDialog(
    context: context,
    transitionDuration: transitionDuration ?? const Duration(milliseconds: 500),
    barrierDismissible: barrierDismissible,
    barrierColor: Theme.of(context).colorScheme.scrim.withOpacity(0.3),
    barrierLabel: 'Material 3 side sheet',
    transitionBuilder: (context, animation, secondaryAnimation, child) {
      return SlideTransition(
        position: Tween(
          begin: (sheetPosition == SheetPosition.right)
              ? const Offset(1, 0)
              : const Offset(-1, 0),
          end: const Offset(0, 0),
        ).animate(animation),
        child: child,
      );
    },
    pageBuilder: (context, animation1, animation2) {
      return Align(
        alignment: (sheetPosition == SheetPosition.right)
            ? Alignment.centerRight
            : Alignment.centerLeft,
        child: SideSheet(
          // enums
          sheetPosition: sheetPosition,
          // strings
          title: title,
          // widgets
          body: body ?? const SizedBox(),
          footer: footer,
          header: header,
          // doubles
          sheetWidth: sheetWidth,
          borderRadius: borderRadius,
          // bools
          showFooterDivider: showFooterDivider,
          showHeaderDivider: showHeaderDivider,
          showSideDivider: showSideDivider,
          showBackButton: showBackButton,
          showActions: showActions,
          safeAreaTop: safeAreaTop,
          safeAreaBottom: safeAreaBottom,
          // callbacks
          confirmActionOnPressed: onConfirm,
          cancelActionOnPressed: onCancel,
          confirmActionText: confirmActionText,
          cancelActionText: cancelActionText,
          showCloseButton: showCloseButton,
          onClose: onClose,
          // Colors
          backgroundColor: backgroundColor,
          surfaceTintColor: surfaceTintColor,
          textColor: textColor,
          iconColor: iconColor,
          dividerColor: dividerColor,
          confirmButtonBgColor: confirmButtonBgColor,
          confirmButtonTextColor: confirmButtonTextColor,
          cancelButtonBgColor: cancelButtonBgColor,
          cancelButtonTextColor: cancelButtonTextColor,
        ),
      );
    },
  ).then(
    (value) {
      if (!barrierDismissible) return;
      onDismiss?.call();
    },
  );
}