0

I implemented a few snack bars, one of which contains a CircularProgressIndicator, for displaying loading messages.

The issue is that in emulator/device, the loading snack bar displays correctly, but in widget testing the snack bar doesn't display at all and is not found by the matcher.

More so, I built a test with golden_toolkit and added each type of snack bar as scenario, but if I include the loading snack bar no other snack bar is displayed anymore.

Here you can see the method which builds the snack bar:

void showLoadingSnackBar({
    Key? key,

    /// The message displayed to the user.
    required String message,

    /// The value of [SnackBar.behavior].
    SnackBarBehavior? behavior,

    /// The value of [SnackBar.width].
    double? width,
  }) {
    final colorScheme = Theme.of(this).colorScheme;
    final foregroundColor = colorScheme.onInverseSurface;
    FoSnackBar.message(
      key: key ?? const ValueKey("FoLoadingSnackBar"),
      behavior: behavior ?? (isIOS ? SnackBarBehavior.floating : null),
      width: width ?? (isIOS ? 250 : null),
      message: message,
      duration: 60,
      icon: SizedBox(
        height: 24,
        width: 24,
        child: Center(
          child: CircularProgressIndicator.adaptive(
            strokeWidth: 2,
            valueColor: AlwaysStoppedAnimation<Color>(foregroundColor),
          ),
        ),
      ),
    ).show(this);
  }

The FoSnackBar.message constructor:

factory FoSnackBar.message({
    Key? key,

    /// The message displayed to the user.
    required String message,

    /// Icon showed at the end of the snackbar.
    Widget? icon,

    /// The value of [SnackBar.behavior].
    SnackBarBehavior? behavior,

    /// The value of [SnackBar.backgroundColor].
    Color? backgroundColor,

    /// The text style of the [message].
    TextStyle? messageStyle,

    /// How many seconds is the message displayed.
    int? duration,

    /// The value [SnackBar.width].
    double? width,
  }) =>
      FoSnackBar(
        key: key,
        behavior: behavior,
        width: width,
        backgroundColor: backgroundColor,
        duration: Duration(seconds: duration ?? 4),
        content: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Flexible(
              child: Text(message, style: messageStyle),
            ),
            if (icon != null) icon,
          ],
        ),
      );

showLoadingSnackBar is a method in an extension on BuildContext, for easy access.

You can see the atached images which are without/with "Loading" snack bar.

System specifications:

Flutter (Channel stable, 3.7.12, on KDE neon 5.27 5.19.0-40-generic, locale ro_RO.UTF-8)
• Flutter version 3.7.12 on channel stable at /path/to/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4d9e56e694 (3 days ago), 2023-04-17 21:47:46 -0400
• Engine revision 1a65d409c7
• Dart version 2.19.6
• DevTools version 2.20.1

Already did flutter clean and pub get. Anyone has any ideeas why is this happening?

Golden test without the "Loading" snack bar. Golden test with the "Loading" snack bar.

adi
  • 417
  • 4
  • 25

0 Answers0