ZetaSnackBar constructor

ZetaSnackBar({
  1. Key? key,
  2. SnackBarBehavior? behavior = SnackBarBehavior.floating,
  3. EdgeInsetsGeometry? margin,
  4. required BuildContext context,
  5. required Widget content,
  6. VoidCallback? onPressed,
  7. ZetaSnackBarType? type,
  8. Widget? leadingIcon,
  9. bool? rounded,
  10. String? actionLabel,
  11. @Deprecated('Use actionLabel instead.' ' Deprecated in 0.12.1') String? deleteActionLabel,
  12. @Deprecated('Use actionLabel instead.' ' Deprecated in 0.12.1') String? viewActionLabel,
  13. String? actionSemanticLabel,
})

Sets basic styles for the SnackBar.

Implementation

ZetaSnackBar({
  super.key,
  super.behavior = SnackBarBehavior.floating,
  super.margin,

  /// Context required to get the theme and colors.
  required BuildContext context,

  /// The main content of the snackbar.
  required Widget content,

  /// Callback to be called when the action button is pressed.
  VoidCallback? onPressed,

  /// Type used to define contextual [SnackBar]. The type defines the styles, icons and behavior.
  ZetaSnackBarType? type,

  /// Icon to display at the start of the content.
  ///
  /// Should be of type [ZetaIcon] or [Icon].
  Widget? leadingIcon,

  /// {@macro zeta-widget-rounded}
  bool? rounded,

  /// Label for the action button.
  ///
  /// Depending on the `type`, the default label will be used; 'Undo' for [ZetaSnackBarType.deletion] and 'View' for [ZetaSnackBarType.view].
  String? actionLabel,

  /// Label for the delete action button.
  ///
  /// If null, 'Delete' will be used.
  @Deprecated('Use actionLabel instead.' ' Deprecated in 0.12.1') String? deleteActionLabel,

  /// Label for the view action button.
  ///
  /// If null, 'View' will be used.
  @Deprecated('Use actionLabel instead.' ' Deprecated in 0.12.1') String? viewActionLabel,

  /// Semantic label for the action button.
  ///
  /// If null, the `actionLabel` will be used.
  String? actionSemanticLabel,
}) : super(
        elevation: 0,
        padding: EdgeInsets.zero,
        backgroundColor: _getBackgroundColorForType(context, type),
        shape: RoundedRectangleBorder(
          borderRadius: type != null
              ? Zeta.of(context).radius.full
              : rounded ?? context.rounded
                  ? Zeta.of(context).radius.minimal
                  : Zeta.of(context).radius.none,
        ),
        content: ZetaRoundedScope(
          rounded: rounded ?? context.rounded,
          child: Padding(
            padding: EdgeInsets.symmetric(vertical: Zeta.of(context).spacing.small),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Flexible(
                  child: Row(
                    children: [
                      _LeadingIcon(type, leadingIcon),
                      Flexible(
                        child: Padding(
                          padding: EdgeInsets.only(left: Zeta.of(context).spacing.medium),
                          child: _Content(type: type, child: content),
                        ),
                      ),
                    ],
                  ),
                ),
                _Action(
                  type: type,
                  actionLabel: actionLabel,
                  onPressed: onPressed,
                  deleteActionLabel: deleteActionLabel,
                  viewActionLabel: viewActionLabel,
                  semanticLabel: actionSemanticLabel,
                ),
              ],
            ),
          ),
        ),
      );