openModalBottomSheet static method

Future openModalBottomSheet(
  1. BuildContext context,
  2. String title,
  3. List contentList,
  4. double itemH,
  5. int maxLines,
)

Implementation

static Future openModalBottomSheet(BuildContext context, String title,
    List contentList, double itemH, int maxLines) async {
  if (contentList == null) return;
  double itemHeight = itemH;
  double contentHeight = contentList.length <= maxLines
      ? contentList.length * itemHeight
      : maxLines * itemHeight;
  print('contentHeight == $contentHeight');
  final option = await showModalBottomSheet(
      context: context,
      isScrollControlled: false,
      useRootNavigator: true,
      barrierColor: Colors.black.withAlpha(25),
      builder: (BuildContext context) {
        return SizedBox(
          height: 22 + 22 + 10 + contentHeight + 20,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const SizedBox(
                height: 22,
              ),
              SizedBox(
                height: 22,
                child: Text(
                  title,
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w500,
                    color: Colors.black26,
                  ),
                ),
              ),
              const SizedBox(
                height: 8,
              ),
              SizedBox(
                height: contentHeight,
                child: ListView(
                    shrinkWrap: true,
                    children: contentList.map((item) {
                      return SizedBox(
                        height: itemHeight,
                        child: ListTile(
                          title: SizedBox(
                            height: itemHeight,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(_getItemName(item), textAlign: TextAlign.center),
                              ],
                            ),
                          ),
                          onTap: () {
                            Navigator.pop(context, item);
                          },
                        ),
                      );
                    }).toList()),
              ),
              const SizedBox(height: 20),
            ],
          ),
        );
      });
  return option;
}