openBottomSheet function

void openBottomSheet(
  1. BuildContext context,
  2. List<Widget> children, {
  3. double? initHeight,
  4. double? maxHeight,
  5. bool? hasInputField,
  6. Color? backgroundColor,
  7. Color? handleColor,
  8. EdgeInsets? padding,
  9. EdgeInsets? margin,
  10. BorderRadius? borderRadius,
})

Implementation

void openBottomSheet(
  BuildContext context,
  List<Widget> children, {
  double? initHeight,
  double? maxHeight,
  bool? hasInputField,
  Color? backgroundColor,
  Color? handleColor,
  EdgeInsets? padding,
  EdgeInsets? margin,
  BorderRadius? borderRadius,
}) {
  showModalBottomSheet(
    context: context,
    backgroundColor: Colors.transparent,
    isScrollControlled: true,
    isDismissible: true,
    builder: (BuildContext context) {
      return DraggableScrollableSheet(
        snap: true,
        expand: false,
        minChildSize: initHeight ?? .20,
        snapSizes: [
          if (initHeight == null) .20,
          initHeight ?? .30,
          maxHeight ?? .60
        ],
        initialChildSize: initHeight ?? .40,
        maxChildSize: maxHeight ?? .60,
        builder: (context, controller) {
          if (hasInputField == true &&
              MediaQuery.of(context).viewInsets == EdgeInsets.zero) {
            if (controller.hasClients) {
              controller.jumpTo(0);
            }
          }

          return Container(
            height: height(context) / 2,
            decoration: BoxDecoration(
              borderRadius: borderRadius ?? BorderRadius.circular(10),
              color: backgroundColor ?? canvasColor(context),
            ),
            margin: margin ??
                const EdgeInsets.all(10).add(
                  EdgeInsets.only(
                    bottom: MediaQuery.of(context).viewInsets == EdgeInsets.zero
                        ? 0
                        : MediaQuery.of(context).viewInsets.bottom,
                  ),
                ),
            padding: padding ?? const EdgeInsets.all(10),
            child: ListView(
              controller: controller,
              children: [
                Container(
                  margin: const EdgeInsets.symmetric(vertical: 10),
                  width: width(context),
                  alignment: Alignment.center,
                  child: Container(
                    width: 60,
                    height: 4,
                    decoration: BoxDecoration(
                      color: handleColor ?? Theme.of(context).iconTheme.color,
                      borderRadius: BorderRadius.circular(10),
                    ),
                  ),
                ),
                ...children
              ],
            ),
          );
        },
      );
    },
  );
}