'Typecast null in return of Future<T>: flutter

I have this code:

Future<T> showCustomBottomSheet<T>({
  required BuildContext context,
  required WidgetBuilder builder,
}) async {

  final result = await showCustomModalBottomSheet(
      isDismissible: true,
      builder: builder,
      ...);

  return result;
}

issue is that if the dialog is dismissed, 'result' is null, and I get an exception thrown

A value of type 'Null' can't be returned from the function 'showCustomBottomSheet' because it has a return type of 'Future'.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source