getOffsetY method Null safety

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

Calculates y-offset for FloatingActionButtonLocations floating at the bottom of the screen.

Implementation

@override
double getOffsetY(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) {
  final double contentBottom = scaffoldGeometry.contentBottom;
  final double bottomContentHeight = scaffoldGeometry.scaffoldSize.height - contentBottom;
  final double bottomSheetHeight = scaffoldGeometry.bottomSheetSize.height;
  final double fabHeight = scaffoldGeometry.floatingActionButtonSize.height;
  final double snackBarHeight = scaffoldGeometry.snackBarSize.height;
  final double safeMargin = math.max(
    kFloatingActionButtonMargin,
    scaffoldGeometry.minViewPadding.bottom - bottomContentHeight + kFloatingActionButtonMargin,
  );

  double fabY = contentBottom - fabHeight - safeMargin;
  if (snackBarHeight > 0.0) {
    fabY = math.min(fabY, contentBottom - snackBarHeight - fabHeight - kFloatingActionButtonMargin);
  }
  if (bottomSheetHeight > 0.0) {
    fabY = math.min(fabY, contentBottom - bottomSheetHeight - fabHeight / 2.0);
  }
  return fabY + adjustment;
}