ZetaBanner constructor

ZetaBanner({
  1. Key? key,
  2. required BuildContext context,
  3. required String title,
  4. IconData? leadingIcon,
  5. ZetaBannerStatus type = ZetaBannerStatus.primary,
  6. bool titleStart = false,
  7. Widget? trailing,
  8. bool? rounded,
  9. 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 titleStart = 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,
        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,
                  ),
                );
              }
            }

            return ZetaRoundedScope(
              rounded: rounded ?? context.rounded,
              child: Semantics(
                label: semanticLabel ?? title,
                child: DefaultTextStyle(
                  style: ZetaTextStyles.labelLarge.copyWith(
                    color: foregroundColor,
                    overflow: TextOverflow.ellipsis,
                  ),
                  child: Row(
                    mainAxisAlignment: titleStart ? MainAxisAlignment.center : MainAxisAlignment.start,
                    children: [
                      if (leadingIcon != null)
                        Padding(
                          padding: EdgeInsets.only(right: Zeta.of(context).spacing.small),
                          child: Icon(
                            leadingIcon,
                            color: foregroundColor,
                            size: Zeta.of(context).spacing.xl_2,
                          ),
                        ),
                      Flexible(child: Text(title)),
                    ],
                  ),
                ),
              ),
            );
          },
        ),
        backgroundColor: _backgroundColorFromType(context, type),
        actions: [
          IconTheme(
            data: IconThemeData(color: _backgroundColorFromType(context, type).onColor),
            child: trailing ?? const Nothing(),
          ),
        ],
      );