如何实现构造showModalBottomSheet
时间: 2023-12-11 19:10:04 浏览: 64
JavaScript中使用构造函数实现继承的代码
要实现构造showModalBottomSheet,你可以在自定义的类中添加一个构造函数,构造函数的参数包含了showModalBottomSheet方法中的所有可选参数,然后在构造函数中调用showModalBottomSheet方法即可。
具体实现如下:
```dart
class MyBottomSheet {
static void show(
BuildContext context, {
required WidgetBuilder builder,
Color backgroundColor = Colors.white,
double elevation = 0.0,
ShapeBorder? shape,
Clip? clipBehavior,
bool isScrollControlled = false,
bool useRootNavigator = false,
bool isDismissible = true,
bool enableDrag = true,
}) {
showModalBottomSheet(
context: context,
builder: builder,
backgroundColor: backgroundColor,
elevation: elevation,
shape: shape,
clipBehavior: clipBehavior,
isScrollControlled: isScrollControlled,
useRootNavigator: useRootNavigator,
isDismissible: isDismissible,
enableDrag: enableDrag,
);
}
}
```
这样就可以通过MyBottomSheet类的静态show方法来构造showModalBottomSheet了。调用方式如下:
```dart
MyBottomSheet.show(
context,
builder: (BuildContext context) => Container(
child: Text('Hello World!'),
),
backgroundColor: Colors.grey[200],
);
```
阅读全文