buildSheetBars function

List<Widget> buildSheetBars({
  1. required BuildContext context,
  2. String primaryActionText = '',
  3. VoidCallback? primaryActionOnTap,
  4. String secondaryActionText = '',
  5. VoidCallback? secondaryActionOnTap,
  6. String ternaryActionText = '',
  7. VoidCallback? ternaryActionOnTap,
  8. String? title = '',
  9. bool showClose = false,
})

Method to build widgets for headerBuilder & bottomBuilder of showZdsBottomSheet This return an array of widgets which contains first element as ZdsSheetHeader and second element as ZdsBottomBar Here widgets gets computed based on the device(Mobile or Tablet).

  • primaryActionText Text for primary button (like Save button)
  • primaryActionOnTap On tap event for primary button
  • secondaryActionText Text for secondary button (like Cancel button)
  • secondaryActionOnTap On tap event for secondary button
  • ternaryActionText Text for ternary button (like Reset button)
  • ternaryActionOnTap On tap event for ternary button
  • title Title for the ZdsSheetHeader
  • showClose Close icon button for the ZdsSheetHeader

Implementation

List<Widget> buildSheetBars({
  required BuildContext context,
  String primaryActionText = '',
  VoidCallback? primaryActionOnTap,
  String secondaryActionText = '',
  VoidCallback? secondaryActionOnTap,
  String ternaryActionText = '',
  VoidCallback? ternaryActionOnTap,
  String? title = '',
  bool showClose = false,
}) {
  final bool isTablet = context.isTablet();
  final num offset = isTablet ? 0 : MediaQuery.of(context).viewPadding.bottom;

  return <Widget>[
    ZdsSheetHeader(
      headerText: title!,
      leading: isTablet && secondaryActionText.isNotEmpty
          ? ZdsButton.text(
              child: Text(secondaryActionText),
            )
          : !isTablet && showClose
              ? IconButton(
                  onPressed: () {
                    secondaryActionOnTap != null
                        ? secondaryActionOnTap()
                        : Navigator.of(context).pop();
                  },
                  icon: const Icon(ZdsIcons.close),
                  tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
                )
              : null,
      trailing: isTablet && primaryActionText.isNotEmpty
          ? ZdsButton.text(
              onTap: primaryActionOnTap,
              child: Text(primaryActionText),
            )
          : null,
    ),
    if (_isBottomBarRequired(
        isTablet, primaryActionText, secondaryActionText, ternaryActionText,))
      ZdsBottomBar(
        minHeight: kBottomBarHeight + offset,
        child: Row(
          children: <Widget>[
            if (isTablet) ...<Widget>[
              if (ternaryActionText.isNotEmpty)
                ZdsButton.text(
                  onTap: ternaryActionOnTap,
                  child: Text(ternaryActionText),
                ),
            ] else ...<Widget>[
              if (ternaryActionText.isNotEmpty)
                ZdsButton.text(
                  onTap: ternaryActionOnTap,
                  child: Text(ternaryActionText),
                ),
              const Spacer(),
              if (secondaryActionText.isNotEmpty && !showClose)
                ZdsButton.outlined(
                  child: Text(secondaryActionText),
                  onTap: () {
                    secondaryActionOnTap != null
                        ? secondaryActionOnTap()
                        : Navigator.of(context).pop();
                  },
                ),
              const SizedBox(width: 9),
              if (primaryActionText.isNotEmpty)
                ZdsButton.filled(
                  onTap: primaryActionOnTap,
                  child: Text(primaryActionText),
                ),
            ],
          ],
        ),
      ),
  ];
}