showBottomSheetCheckboxIten<T> function Null safety

Future<List<T>>? showBottomSheetCheckboxIten<T>(
  1. dynamic context,
  2. {required List<ModernFormBottomSheetModel<T>> suggestions,
  3. required List<ModernFormBottomSheetModel<T>>? value,
  4. required String title,
  5. TextStyle? titleStyle,
  6. bool? forceMenu = false}
)

Implementation

Future<List<T>>? showBottomSheetCheckboxIten<T>(
  context, {
  required List<ModernFormBottomSheetModel<T>> suggestions,
  required List<ModernFormBottomSheetModel<T>>? value,
  required String title,
  TextStyle? titleStyle,
  bool? forceMenu = false,
}) async {
  List<T> _listSelected =
      List<T>.from(value?.map((e) => e.value).toList() ?? []);

  if (forceMenu == null) {
    forceMenu = false;
  }
  if (MediaQuery.of(context).size.width > ModernFormUtils.webBreakdown ||
      forceMenu) {
    List<menu.PopupMenuEntry<T>> items = [];

    suggestions.forEach((element) {
      items.add(menu.PopupMenuItem<T>(
        value: element.value,
        onTapEnabled: false,
        child: _ItenCheckBox(
          title: element.text,
          isSelected: _listSelected.contains(element.value),
          onChanged: (value) {
            if (_listSelected.contains(element.value)) {
              _listSelected.remove(element.value);
            } else {
              _listSelected.add(element.value);
            }
          },
        ),
      ));
    });
    if (items.isNotEmpty) {
      await menu.showMenu(
        context: context,
        position: menu.modernFormPopupMenuPosition(
            context, menu.ModernFormPopupMenuLocation.BottomLeft),
        items: items,
        maxHeight: MediaQuery.of(context).size.height * .3,
      );
    }
  } else {
    List<Widget> widgets = <Widget>[];

    suggestions.forEach(
      (element) => widgets.add(
        _ItenCheckBox(
          title: element.text,
          isSelected: _listSelected.contains(element.value),
          onChanged: (value) {
            if (_listSelected.contains(element.value)) {
              _listSelected.remove(element.value);
            } else {
              _listSelected.add(element.value);
            }
          },
        ),
      ),
    );
    await showModalBottomSheet(
      isScrollControlled: true,
      context: context,
      builder: (context) {
        return ConstrainedBox(
          constraints: BoxConstraints(
              maxHeight: MediaQuery.of(context).size.height * .7),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              ModernFormBottonSheetLabel(
                label: title,
                labelStyle: titleStyle,
              ),
              Expanded(
                child: ListView(
                  padding:
                      EdgeInsets.symmetric(vertical: ScreenUtil().setSp(15)),
                  children: widgets,
                ),
              ),
            ],
          ),
        );
      },
    );
  }
  return _listSelected;
}