showModernFormFilterPopupMenu<T> function Null safety

Future<T?> showModernFormFilterPopupMenu<T>(
  1. BuildContext context,
  2. {required List<ModernFormBottomSheetModel<T>> list,
  3. String? title,
  4. ModernFormPopupMenuLocation? menuLocation,
  5. bool? forceMenu}
)

Implementation

Future<T?> showModernFormFilterPopupMenu<T>(
  BuildContext context, {
  required List<ModernFormBottomSheetModel<T>> list,
  String? title,
  menu.ModernFormPopupMenuLocation? menuLocation,
  bool? forceMenu,
}) async {
  if (forceMenu == null) {
    forceMenu = list.length <= 5;
  }
  Size size = MediaQuery.of(context).size;
  if (size.width > ModernFormUtils.webBreakdown || forceMenu) {
    List<menu.PopupMenuEntry<T>> items = [];

    list.forEach((element) {
      items.add(menu.PopupMenuItem(
        value: element.value,
        child: _Iten(
          title: element.text,
          textColor: element.textColor,
        ),
      ));
    });

    if (items.isNotEmpty) {
      return await menu.showMenu<T>(
        context: context,
        position: menu.modernFormPopupMenuPosition(context, menuLocation),
        items: items,
        maxHeight: size.width > ModernFormUtils.webBreakdown
            ? size.height * .5
            : size.height * .3,
      );
    } else {
      return null;
    }
  }

  return await showModalBottomSheet(
    isScrollControlled: true,
    context: context,
    builder: (context) {
      return ConstrainedBox(
        constraints: BoxConstraints(maxHeight: ScreenUtil().screenHeight * .6),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            ModernFormBottonSheetLabel(label: title ?? ""),
            Expanded(
              child: ListView.builder(
                  padding: EdgeInsets.only(
                      bottom: ScreenUtil().setHeight(15),
                      top: ScreenUtil().setHeight(7)),
                  itemCount: list.length,
                  itemBuilder: (context, index) {
                    ModernFormBottomSheetModel iten = list[index];
                    return _Iten(
                      title: iten.text,
                      textColor: iten.textColor,
                      onTap: () {
                        Navigator.pop(context, iten.value);
                      },
                    );
                  }),
            ),
          ],
        ),
      );
    },
  );
}