bottomSheet static method

Future<void> bottomSheet(
  1. BuildContext context, {
  2. Color? backgroundColor,
  3. Color? color,
  4. bool isScrollControlled = false,
  5. required List<Widget> builder(
    1. BuildContext context,
    2. VoidCallback onClose
    ),
  6. 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),
                ),
              ),
            ),
          ),
        ),
      );
    },
  );
}