bottomSheet static method
Future<void>
bottomSheet(
- BuildContext context, {
- Color? backgroundColor,
- Color? color,
- bool isScrollControlled = false,
- required List<
Widget> builder(- BuildContext context,
- VoidCallback onClose
- EdgeInsetsGeometry contentPadding = const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
Display the bottom sheet as a modal.
The widget to be displayed is passed to builder
.
Specify the background color with backgroundColor
and the text color with color
.
モーダルとしてのボトムシートを表示します。
builder
には表示するウィジェットを渡します。
backgroundColor
で背景色、color
でテキストカラーを指定します。
Implementation
static Future<void> bottomSheet(
BuildContext context, {
Color? backgroundColor,
Color? color,
bool isScrollControlled = false,
required List<Widget> Function(BuildContext context, VoidCallback onClose)
builder,
EdgeInsetsGeometry contentPadding =
const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
}) async {
final overlay = Navigator.of(context).overlay;
if (overlay == null) {
return;
}
final foregroundColor = color ??
Theme.of(context).dialogTheme.iconColor ??
Theme.of(context).colorScheme.onSurface;
backgroundColor ??= Theme.of(context).dialogTheme.backgroundColor ??
Theme.of(context).colorScheme.surface;
void onClose() {
Navigator.of(context, rootNavigator: true).pop();
}
await showModalBottomSheet(
context: overlay.context,
isScrollControlled: isScrollControlled,
backgroundColor: backgroundColor,
useSafeArea: true,
builder: (context) {
return ColoredBox(
color: backgroundColor!,
child: SafeArea(
top: false,
child: IconTheme(
data: IconThemeData(color: foregroundColor),
child: DefaultTextStyle(
style: TextStyle(color: foregroundColor),
child: Padding(
padding: contentPadding,
child: Column(
mainAxisSize: MainAxisSize.min,
children: builder.call(context, onClose),
),
),
),
),
),
);
},
);
}