Unverified Commit 1f3d423f authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Step 1: SnackBarBehavior.floating offset fix - Soft breaking change (#50597)

* Adds an opt-in flag to fix floating snackbar's offset when no floating action button is present. This flag will be removed once the migration for the fix is complete.
Co-authored-by: 's avatarfilaps <filip1997.28@mail.ru>
parent 550c82d5
......@@ -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;
......@@ -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));
}
......@@ -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}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment