csShowBottomSheet function

dynamic csShowBottomSheet(
  1. BuildContext context, {
  2. String? title,
  3. required List<String> actions,
  4. String cancel = '取消',
  5. DidSelectIndexCallback? indexCallback,
  6. DidSelectCancelCallback? cancelCallback,
})

Implementation

csShowBottomSheet(
  BuildContext context, {
  String? title,
  required List<String> actions,
  String cancel = '取消',
  DidSelectIndexCallback? indexCallback,
  DidSelectCancelCallback? cancelCallback,
}) {
  List<Widget> widgets = [];
  actions.asMap().forEach((int index, String value) {
    widgets.add(CupertinoActionSheetAction(
      onPressed: () {
        Navigator.pop(context);
        if (indexCallback != null) {
          indexCallback(index);
        }
      },
      child: Text(value),
    ));
  });
  showCupertinoModalPopup(
      context: context,
      builder: (BuildContext context) {
        var sheet = CupertinoActionSheet(
          title: Text(title ?? ""),
          actions: widgets,
          cancelButton: cancel.isEmptyString
              ? SizedBox.shrink()
              : CupertinoActionSheetAction(
                  child: Text(cancel),
                  onPressed: () {
                    Navigator.pop(context);
                    if (cancelCallback != null) {
                      cancelCallback();
                    }
                  },
                ),
        );
        return sheet;
      });
}