showActionSheet<T> function
Future<T?>
showActionSheet<T>({
- required BuildContext context,
- List<
ActionItem> ? actions, - Widget? content,
- ChoiceConfig? choiceConfig,
- TopActionItem? topActionItem,
- BottomActionItem? bottomActionItem,
- Color? barrierColor,
- Color? actionSheetColor,
- bool isScrollControlled = false,
- bool isDismissible = true,
- bool enableDrag = true,
通用ActionSheet
topActionItem
头部组件, 如果为null则不显示
actions
中间的按钮组件
content
自定义中间区域
choiceConfig
选择框
bottomActionItem
底部取消按钮, 如果为null则不显示
barrierColor
遮罩颜色, 不能为透明色
actionSheetColor
组件的背景颜色
isScrollControlled
是否时全屏还是半屏
isDismissible
点击背景是否可以关闭
enableDrag
是否允许拖拽
Implementation
Future<T?> showActionSheet<T>({
required BuildContext context,
List<ActionItem>? actions,
Widget? content,
ChoiceConfig? choiceConfig,
TopActionItem? topActionItem,
BottomActionItem? bottomActionItem,
Color? barrierColor,
Color? actionSheetColor,
bool isScrollControlled = false,
bool isDismissible = true,
bool enableDrag = true,
}) async {
assert(barrierColor != Colors.transparent, 'The barrier color cannot be transparent.');
// 当有头部并且有标题的时候, 设置顶部圆角
final roundedRectangleBorder = topActionItem == null
? null
: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
));
return showModalBottomSheet<T>(
context: context,
elevation: 0,
isScrollControlled: isScrollControlled,
isDismissible: isDismissible,
enableDrag: enableDrag,
backgroundColor: actionSheetColor ?? Theme.of(context).dialogBackgroundColor,
barrierColor: barrierColor,
shape: roundedRectangleBorder,
builder: (ctx) {
return _ActionSheet(
actions: actions,
content: content,
choiceConfig: choiceConfig,
topActionItem: topActionItem,
bottomActionItem: bottomActionItem);
});
}