getOffsetY method

  1. @override
double getOffsetY (
  1. ScaffoldPrelayoutGeometry scaffoldGeometry,
  2. double adjustment
)
override

Calculates y-offset for FloatingActionButtonLocations floating over the Scaffold.bottomNavigationBar so that the center of the floating action button lines up with the top of the bottom navigation bar.

Implementation

@override
double getOffsetY(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) {
  final double contentBottom = scaffoldGeometry.contentBottom;
  final double contentMargin = scaffoldGeometry.scaffoldSize.height - contentBottom;
  final double bottomViewPadding = scaffoldGeometry.minViewPadding.bottom;
  final double bottomSheetHeight = scaffoldGeometry.bottomSheetSize.height;
  final double fabHeight = scaffoldGeometry.floatingActionButtonSize.height;
  final double snackBarHeight = scaffoldGeometry.snackBarSize.height;
  final double safeMargin = bottomViewPadding > contentMargin ? bottomViewPadding : 0.0;

  double fabY = contentBottom - fabHeight / 2.0 - safeMargin;
  // The FAB should sit with a margin between it and the snack bar.
  if (snackBarHeight > 0.0)
    fabY = math.min(fabY, contentBottom - snackBarHeight - fabHeight - kFloatingActionButtonMargin);
  // The FAB should sit with its center in front of the top of the bottom sheet.
  if (bottomSheetHeight > 0.0)
    fabY = math.min(fabY, contentBottom - bottomSheetHeight - fabHeight / 2.0);
  final double maxFabY = scaffoldGeometry.scaffoldSize.height - fabHeight - safeMargin;
  return math.min(maxFabY, fabY);
}