Skip to content

Floating SnackBar incompatible with certain FloatingActionButtonLocations #128150

@jdsareault

Description

@jdsareault

Is there an existing issue for this?

Steps to reproduce

  1. Create an app with a Scaffold and a FloatingActionButton
  2. Set FloatingActionButtonLocation so that the button is at the top of the screen, such as FloatingActionButtonLocation.startTop.
  3. Call a SnackBar with behavior of SnackBarBehavior.floating.

Expected results

Display a SnackBar on a visible portion of the screen. Either at the bottom of the screen, or below the FloatingActionButton.

Actual results

SnackBar tries to float above the FloatingActionButton, causing it to display off-screen (or above the SafeArea, and partially off-screen).

Code sample

Code sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(title: 'Snackbar Position Issue'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({
    Key? key,
    required this.title,
  }) : super(key: key);

  void _showSnackBar(BuildContext context) {
    SnackBar mySnackBar = const SnackBar(
      content: Text('Snack Time'),
      behavior: SnackBarBehavior.floating,
      width: 300,
    );
    ScaffoldMessenger.of(context).showSnackBar(mySnackBar);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: const Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Press the Ice Cream to call SnackBar'),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _showSnackBar(context);
        },
        tooltip: 'Call SnackBar',
        child: const Icon(Icons.icecream),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.startTop,
    );
  }
}

Screenshots or Video

Screenshots of SnackBar visible halfway off-screen

Screenshot from 2023-06-02 18-43-32

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.3, on Pop!_OS 22.04 LTS 5.18.10-76051810-generic, locale en_US.UTF-8)
    • Flutter version 3.10.3 on channel stable at /home/user/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f92f44110e (23 hours ago), 2023-06-01 18:17:33 -0500
    • Engine revision 2a3401c9bb
    • Dart version 3.0.3
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /home/user/Android/Sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /home/user/Downloads/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2021.3)
    • Android Studio at /home/user/Downloads/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.78.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.66.0

[✓] Connected device (3 available)
    • Pixel 3a XL (mobile) • 94PAX0EFHR • android-arm64  • Android 12 (API 32)
    • Linux (desktop)      • linux      • linux-x64      • Pop!_OS 22.04 LTS 5.18.10-76051810-generic
    • Chrome (web)         • chrome     • web-javascript • Google Chrome 109.0.5414.74

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

• No issues found!

Metadata

Metadata

Assignees

Labels

a: qualityA truly polished experienced: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.found in release: 3.10Found to occur in 3.10found in release: 3.12Found to occur in 3.12frameworkflutter/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 teamtriaged-designTriaged 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