getVerticalOffset static method

double getVerticalOffset({
  1. required BuildContext context,
  2. ToastGravity? gravity,
  3. double? verticalOffset,
})

获取默认设置的垂直间距

Implementation

static double getVerticalOffset({
  required BuildContext context,
  ToastGravity? gravity,
  double? verticalOffset,
}) {
  final double _verticalOffset = verticalOffset ?? 0;
  final double defaultOffset;
  switch (gravity) {
    case ToastGravity.bottom:
      final offset = verticalOffset ?? _defaultBottomOffset;
      defaultOffset = MediaQuery.of(context).viewInsets.bottom + offset;
      break;
    case ToastGravity.top:
      final offset = verticalOffset ?? _defaultTopOffset;
      defaultOffset = MediaQuery.of(context).viewInsets.top + offset;
      break;
    case ToastGravity.center:
    default:
      defaultOffset = verticalOffset ?? 0;
  }

  return defaultOffset + _verticalOffset;
}