ZetaSystemBanner constructor

ZetaSystemBanner({
  1. Key? key,
  2. required BuildContext context,
  3. required String title,
  4. IconData? leadingIcon,
  5. ZetaSystemBannerStatus type = ZetaSystemBannerStatus.primary,
  6. bool titleCenter = false,
  7. Widget? trailing,
  8. bool? rounded,
  9. String? semanticLabel,
})

Constructor for ZetaSystemBanner. See MaterialBanner for more information.

Implementation

ZetaSystemBanner({
  super.key,
  required BuildContext context,

  /// The title of the banner.
  required String title,

  /// The leading icon for the banner.
  IconData? leadingIcon,

  /// The type of banner. See [ZetaSystemBannerStatus].
  ZetaSystemBannerStatus type = ZetaSystemBannerStatus.primary,

  /// Whether the title should be centered.
  bool titleCenter = false,

  /// The trailing widget for the banner.
  Widget? trailing,

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

  /// The semantic label for the banner.
  ///
  /// If this is null, the title will be used.
  String? semanticLabel,
}) : super(
        dividerColor: Colors.transparent,
        onVisible: () {
          if (PlatformIs.android) {
            final backgroundColor = _backgroundColorFromType(context, type);

            SystemChrome.setSystemUIOverlayStyle(
              SystemUiOverlayStyle(
                statusBarColor: backgroundColor,
                systemNavigationBarIconBrightness: backgroundColor.isDark ? Brightness.light : Brightness.dark,
              ),
            );
          }
        },
        content: Builder(
          builder: (context) {
            final foregroundColor = Zeta.of(context).colors.mainInverse;

            return ZetaRoundedScope(
              rounded: rounded ?? context.rounded,
              child: Semantics(
                label: semanticLabel ?? title,
                child: DefaultTextStyle(
                  style: ZetaTextStyles.labelLarge.copyWith(
                    color: foregroundColor,
                    overflow: TextOverflow.ellipsis,
                  ),
                  child: Stack(
                    alignment: titleCenter ? Alignment.center : Alignment.centerLeft,
                    children: [
                      if (leadingIcon != null)
                        Positioned(
                          left: 0,
                          child: Padding(
                            padding: EdgeInsets.only(right: Zeta.of(context).spacing.small),
                            child: Icon(
                              leadingIcon,
                              color: foregroundColor,
                              size: Zeta.of(context).spacing.xl_2,
                            ),
                          ),
                        ),
                      Padding(
                        padding:
                            !titleCenter && leadingIcon != null ? const EdgeInsets.only(left: 40) : EdgeInsets.zero,
                        child: Text(
                          title,
                          style: ZetaTextStyles.labelLarge.copyWith(
                            color: foregroundColor,
                          ),
                        ),
                      ),
                      if (trailing != null)
                        Positioned(
                          right: 0,
                          child: IconTheme(
                            data: IconThemeData(color: foregroundColor),
                            child: trailing,
                          ),
                        ),
                    ],
                  ),
                ),
              ),
            );
          },
        ),
        backgroundColor: _backgroundColorFromType(context, type),
        actions: [const Nothing()],
      );