showBottomSheetProfiles function Null safety

Future showBottomSheetProfiles(
  1. dynamic context,
  2. {required List<ModernFormBottomSheetProfileModel> list,
  3. required String? title,
  4. TextStyle? titleStyle,
  5. bool? forceMenu = false}
)

Implementation

Future<dynamic> showBottomSheetProfiles(
  context, {
  required List<ModernFormBottomSheetProfileModel> list,
  required String? title,
  TextStyle? titleStyle,
  bool? forceMenu = false,
}) async {
  if (forceMenu == null) {
    forceMenu = false;
  }
  if (MediaQuery.of(context).size.width > ModernFormUtils.webBreakdown ||
      forceMenu) {
    List<menu.PopupMenuEntry<dynamic>> items = [];

    list.forEach((element) {
      items.add(menu.PopupMenuItem(
        value: element.returnValue,
        child: _ProfileIten(
          title: element.name,
          image: element.imageUrl,
        ),
      ));
    });
    if (items.isNotEmpty) {
      return await menu.showMenu(
        context: context,
        position: menu.modernFormPopupMenuPosition(
            context, menu.ModernFormPopupMenuLocation.BottomLeft),
        items: items,
        maxHeight: MediaQuery.of(context).size.height * .3,
      );
    } else {
      return null;
    }
  }

  List<Widget> widgets = <Widget>[];
  list.forEach((element) => widgets.add(_ProfileIten(
        image: element.imageUrl,
        title: element.name,
        description: element.description,
        onTap: () {
          Navigator.pop(context, element.returnValue);
        },
      )));

  return await showModalBottomSheet(
    isScrollControlled: true,
    context: context,
    builder: (context) {
      return ConstrainedBox(
        constraints:
            BoxConstraints(maxHeight: MediaQuery.of(context).size.height * .6),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            ModernFormBottonSheetLabel(
              label: title,
              labelStyle: titleStyle,
            ),
            Expanded(
              child: ListView(
                padding: EdgeInsets.symmetric(vertical: ScreenUtil().setSp(15)),
                shrinkWrap: true,
                children: widgets,
              ),
            ),
          ],
        ),
      );
    },
  );
}