presentSheet<T> static method

Future<void> presentSheet<T>({
  1. String title = "Popup",
  2. bool isFullScreen = true,
  3. bool useRootContext = false,
  4. Color? contentColor,
  5. EdgeInsets? contentPadding,
  6. dynamic onChanged(
    1. T result
    )?,
  7. required BuildContext context,
  8. required Builder builder,
})

Implementation

static Future<void> presentSheet<T>({
  String title = "Popup",
  bool isFullScreen = true,
  bool useRootContext = false,
  Color? contentColor,
  EdgeInsets? contentPadding,
  Function(T result)? onChanged,
  required BuildContext context,
  required Builder builder,
}) async {
  final result = await showModalBottomSheet(
    isScrollControlled: true,
    enableDrag: true,
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
    backgroundColor: Colors.white,
    context: context,
    builder: (context) => ConstrainedBox(
      constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(context).height * 0.85),
      child: Padding(
        padding: MediaQuery.viewInsetsOf(context),
        child: IntrinsicHeight(
          child: Column(
            children: [
              AppBar(
                title: Padding(
                  padding: const EdgeInsets.all(0),
                  child: Text(
                    title,
                    style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
                  ),
                ),
                automaticallyImplyLeading: false,
                actions: [
                  IconButton(
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                      icon: const Icon(Icons.close))
                ],
              ),
              ConstrainedBox(
                constraints: BoxConstraints(
                    maxHeight:
                        MediaQuery.sizeOf(context).height * 0.85 - 64 - MediaQuery.viewInsetsOf(context).bottom),
                child: SizedBox(
                  child: SingleChildScrollView(
                    child: Padding(
                      padding: contentPadding ?? EdgeInsets.zero,
                      child: Column(
                        children: [
                          useRootContext ? builder.build(context) : builder,
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    ),
  );
  if (result != null && onChanged != null) {
    onChanged(result);
  }
}