Skip to content

Flutter snackbar position incorrect when useMaterial3=true and locale=he (suspected Flutter framework bug) #140125

@joelrose2

Description

@joelrose2

Is there an existing issue for this?

Steps to reproduce

After updating my app to Material3 (with no changes to the app code itself), a strange thing is happening: the snackbar appears off-center, and partially off the screen.

After lots of investigation, I discovered this: if I set MaterialApp(theme: ThemeData(useMaterial3: false)), the snackbar returns to appearing normally (centered in the screen).

Likewise, if I leave useMaterial3: true and remove the MaterialApp(locale: const Locale("he")) definition, the snackbar also returns to appearing normally (centered in the screen). But, with useMaterial3=true and locale=he the snackbar appears in the wrong place (before changing the app to Material3, the snackbar worked as expected).

The app's MaterialApp definition is below, as is the snackbar code.

Note: When I use the Widget Inspector, I can see an empty rectangular area that is pushing the snackbar over to the right, but that rectangular area is not defined anywhere in my code, and it does not respond to clicks in the Widget Inspector, and it does not appear in the widget tree shown in the Widget Inspector. See the image I prepared, below.

(Side note, which you can see in the image: in the Widget Inspector mode, it shows a floating Search button that does not exist in my code and that does not appear when the application itself is running!).

This really appears to me to be a bug in Flutter's framework code (although I'd be happy to hear otherwise) because there is no change in the snackbar code itself (or any other actual code in the app), just the MaterialApp initialization specs.

Expected results

The snackbar should be centered in the screen regardless of the of the locale setting.

Actual results

When using Material3 and locale=he, the snackbar is in the wrong position.

Code sample

Stateless widget that launches the app:
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: txtAppTitle,
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
        primarySwatch: materialColor(colorDarkBlue),
        colorScheme: ColorScheme.fromSeed(
          seedColor: materialColor(colorDarkBlue),
          primary: materialColor(colorDarkBlue),
        ),
        appBarTheme: const AppBarTheme(
            backgroundColor: colorLightBlue,
            foregroundColor: colorWhite,
            systemOverlayStyle: SystemUiOverlayStyle(
                systemNavigationBarColor: colorLightGrey,
                systemNavigationBarDividerColor: colorDarkGrey,
                systemNavigationBarIconBrightness: Brightness.dark)),
        materialTapTargetSize: MaterialTapTargetSize.padded,
      ),
      locale: const Locale("he"),
      supportedLocales: const [
        Locale('he'),
        Locale('en'),
      ],
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      home: const HomeScreen(),
    );
  }
Snackbar code:
  SnackBar snackBar = SnackBar(
    behavior: SnackBarBehavior.floating,
    duration: const Duration(seconds: 3),
    width: 330,
    padding: const EdgeInsetsDirectional.fromSTEB(5, 6, 5, 6),
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(35.0),
    ),
    content: Text(
      thisMessage,
      style: const TextStyle(fontSize: 15, color: colorWhite),
      textAlign: TextAlign.center,
    ),
  );
  ScaffoldMessenger.of(context).showSnackBar(snackBar);

Screenshots or Video

Appearance comparison, with `locale=he` and `useMaterial3=true` versus when *either* of these is set differently (i.e., `locale=en` or `useMaterial3=false`)

snackbar

Logs

No response

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.16.0, on Microsoft Windows [Version 10.0.19045.3693], locale en-US)
    • Flutter version 3.16.0 on channel stable at C:\Users\user\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db7ef5bf9f (4 weeks ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\user\AppData\Local\Android\Sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = c:\Users\user\AppData\Local\Android
    • Java binary at: C:\Users\user\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\223.8836.35.2231.11090377\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop Windows apps (Visual Studio Community 2017 15.8.1)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
    • Visual Studio Community 2017 version 15.8.28010.2003
    • Windows 10 SDK version 10.0.17134.0
    X Visual Studio 2019 or later is required.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2022.3)
    • Android Studio at C:\Users\user\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\223.8836.35.2231.11090377
    • Flutter plugin version 76.3.2
    • Dart plugin version 223.8977
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)

[√] VS Code (version 1.85.0)
    • VS Code at C:\Users\user\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.78.0

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.3693]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 120.0.6099.71
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 119.0.2151.97

[√] Network resources
    • All expected network resources are available.

Metadata

Metadata

Assignees

Labels

a: internationalizationSupporting other languages or locales. (aka i18n)f: material designflutter/packages/flutter/material repository.found in release: 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions