Skip to content
Merged
31 changes: 28 additions & 3 deletions packages/flutter/lib/src/material/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(shihaohong): remove ignoring deprecated member use analysis
// when Scaffold.shouldSnackBarIgnoreFABRect parameter is removed.
// ignore_for_file: deprecated_member_use_from_same_package

import 'dart:async';
import 'dart:collection';
import 'dart:math' as math;
Expand Down Expand Up @@ -547,9 +551,19 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
if (snackBarSize == Size.zero) {
snackBarSize = layoutChild(_ScaffoldSlot.snackBar, fullWidthConstraints);
}
final double snackBarYOffsetBase = floatingActionButtonRect != null && isSnackBarFloating
? floatingActionButtonRect.top
: contentBottom;

double snackBarYOffsetBase;
if (Scaffold.shouldSnackBarIgnoreFABRect) {
if (floatingActionButtonRect.size != Size.zero && isSnackBarFloating)
snackBarYOffsetBase = floatingActionButtonRect.top;
else
snackBarYOffsetBase = contentBottom;
} else {
snackBarYOffsetBase = floatingActionButtonRect != null && isSnackBarFloating
? floatingActionButtonRect.top
: contentBottom;
}

positionChild(_ScaffoldSlot.snackBar, Offset(0.0, snackBarYOffsetBase - snackBarSize.height));
}

Expand Down Expand Up @@ -1299,6 +1313,17 @@ class Scaffold extends StatefulWidget {
/// 20.0 will be added to `MediaQuery.of(context).padding.left`.
final double drawerEdgeDragWidth;

/// This flag is deprecated and fixes and issue with incorrect clipping
/// and positioning of the [SnackBar] set to [SnackBarBehavior.floating].
@Deprecated(
'This property controls whether to clip and position the snackbar as '
'if there is always a floating action button, even if one is not present. '
'It exists to provide backwards compatibility to ease migrations, and will '
'eventually be removed. '
'This feature was deprecated after v1.15.3.'
)
static bool shouldSnackBarIgnoreFABRect = false;

/// The state from the closest instance of this class that encloses the given context.
///
/// {@tool dartpad --template=freeform}
Expand Down
Loading