ZetaBanner constructor

ZetaBanner({
  1. Key? key,
  2. required BuildContext context,
  3. required String title,
  4. IconData? leadingIcon,
  5. ZetaBannerStatus type = ZetaBannerStatus.primary,
  6. bool titleCenter = false,
  7. @Deprecated('Use titleCenter instead. ' 'This attribute has been renamed as of 0.18.0') bool? titleStart,
  8. Widget? trailing,
  9. bool? rounded,
  10. String? semanticLabel,
})

Constructor for ZetaBanner. See MaterialBanner for more information.

Implementation

ZetaBanner({
  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 [ZetaBannerStatus].
  ZetaBannerStatus type = ZetaBannerStatus.primary,

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

  /// Whether the title should be centered.
  @Deprecated('Use titleCenter instead. ' 'This attribute has been renamed as of 0.18.0') bool? titleStart,

  /// 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,
        content: Builder(
          builder: (context) {
            final backgroundColor = _backgroundColorFromType(context, type);
            final foregroundColor = backgroundColor.onColor;
            if (!kIsWeb && PlatformIs.android && context.mounted) {
              // ignore: invalid_use_of_visible_for_testing_member
              final statusBarColor = SystemChrome.latestStyle?.statusBarColor;
              if (statusBarColor != backgroundColor) {
                SystemChrome.setSystemUIOverlayStyle(
                  SystemUiOverlayStyle(
                    statusBarColor: backgroundColor,
                    systemNavigationBarIconBrightness: backgroundColor.isDark ? Brightness.light : Brightness.dark,
                  ),
                );
              }
            }

            // ignore: no_leading_underscores_for_local_identifiers
            final _titleCenter = titleStart ?? titleCenter;
            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: Zeta.of(context).colors.textInverse,
                          ),
                        ),
                      ),
                      if (trailing != null)
                        Positioned(
                          right: 0,
                          child: IconTheme(
                            data: IconThemeData(color: _backgroundColorFromType(context, type).onColor),
                            child: trailing,
                          ),
                        ),
                    ],
                  ),
                ),
              ),
            );
          },
        ),
        backgroundColor: _backgroundColorFromType(context, type),
        actions: [const Nothing()],
      );