showBottomSheet static method

void showBottomSheet(
  1. BuildContext context, {
  2. String? title,
  3. required String? body,
  4. String? background,
  5. String? textColor,
  6. String? url,
  7. int? scale,
  8. required dynamic onOkPressed(),
})

Implementation

static void showBottomSheet(
  BuildContext context, {
  String? title,
  required String? body,
  String? background,
  String? textColor,
  String? url,
  int? scale,
  required Function() onOkPressed,
}) {
  // var isDarkTheme = Theme.of(context).brightness == Brightness.dark;
  showModalBottomSheet(
    context: context,
    isDismissible: false,
    // isScrollControlled: true,
    backgroundColor: Colors.transparent,
    builder: (context) {
      return SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.only(
              top: padding,
              bottom: padding * 2,
              left: padding,
              right: padding),
          decoration: BoxDecoration(
            color: background != null
                ? Util.hexToColor(background)
                : Util.isDarkMode
                    ? Colors.black
                    : Colors.white,
            borderRadius: const BorderRadius.only(
              topLeft: Radius.circular(8),
              topRight: Radius.circular(8),
            ),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              title != null
                  ? Text(
                      title,
                      style: TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                        color: textColor != null
                            ? Util.hexToColor(textColor)
                            : null,
                      ),
                    )
                  : const SizedBox(),
              const SizedBox(height: 16),
              body != null
                  ? body
                          .toString()
                          .startsWith(WebviewUtil.bodyStartsWithHtmlString)
                      ? Container(
                          height: 200,
                          constraints: const BoxConstraints(
                            minHeight: 200, // Minimum height
                            maxHeight: 500, // Maximum height
                          ),
                          // width: double.infinity,
                          child: WebviewUtil.getWebView(),
                        )
                      : Text(
                          body,
                          style: TextStyle(
                            color: textColor != null
                                ? Util.hexToColor(textColor)
                                : null,
                          ),
                        )
                  : SizedBox(
                      height: 200,
                      width: 200,
                      child: WebviewUtil.getWebView(),
                    ),
              Row(
                children: [
                  const Spacer(),
                  ElevatedButton(
                    onPressed: () {
                      Navigator.pop(context);
                      onOkPressed();
                    },
                    child: const Text("OK"),
                  ),
                ],
              )
            ],
          ),
        ),
      );
    },
  );

  WebviewUtil.load(url, body);
}