getOffsetY method
- ScaffoldPrelayoutGeometry scaffoldGeometry,
- 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 center 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 fabHeight = scaffoldGeometry.floatingActionButtonSize.height;
double safeMargin;
if (contentMargin > bottomViewPadding + fabHeight) {
// If contentMargin is higher than bottomViewPadding enough to display the
// FAB without clipping, don't provide a margin
safeMargin = 0.0;
} else {
safeMargin = bottomViewPadding;
}
// This is to compute the distance between the content bottom to the top edge
// of the floating action button. This can be negative if content margin is
// too small.
final double contentBottomToFabTop = (contentMargin - bottomViewPadding - fabHeight) / 2.0;
final double fabY = contentBottom + contentBottomToFabTop;
final double maxFabY = scaffoldGeometry.scaffoldSize.height - fabHeight - safeMargin;
return math.min(maxFabY, fabY);
}