bottom function

Widget bottom({
  1. dynamic child,
  2. Widget? customChild,
  3. double? maxHeight,
  4. String? title,
  5. Color? backgroundTitleColor,
  6. bool full = false,
  7. dynamic onScreenTap,
  8. required BuildContext context,
})

Implementation

Widget bottom({
  child,
  Widget? customChild,
  double? maxHeight,
  String? title,
  Color? backgroundTitleColor,
  bool full = false,
  onScreenTap,
  required BuildContext context,
}) {
  return GestureDetector(
    onTap: () {
      Navigator.pop(context);
    },
    child: SizedBox(
      height: MediaQuery.of(context).size.height,
      child: Scaffold(
        backgroundColor: Colors.transparent,
        body: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            SingleChildScrollView(
              child: ConstrainedBox(
                constraints: BoxConstraints(
                  maxHeight: MediaQuery.of(context).size.height * (maxHeight ?? 0.8),
                ),
                child: GestureDetector(
                  onTap: () {
                    if (onScreenTap != null) {
                      onScreenTap();
                    }
                    final FocusScopeNode currentScope = FocusScope.of(context);
                    if (!currentScope.hasPrimaryFocus && currentScope.hasFocus) {
                      FocusManager.instance.primaryFocus!.unfocus();
                    }
                    SystemChrome.restoreSystemUIOverlays();
                  },
                  child: Padding(
                    padding: EdgeInsets.zero,
                    child: Container(
                      decoration: title == null
                          ? null
                          : BoxDecoration(
                              color: backgroundTitleColor ?? Theme.of(context).primaryColor,
                              borderRadius: const BorderRadius.only(
                                topLeft: Radius.circular(25.0),
                                topRight: Radius.circular(25.0),
                              ),
                            ),
                      child: Column(
                        mainAxisSize: full ? MainAxisSize.max : MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          title == null
                              ? const SizedBox()
                              : Padding(
                                  padding: const EdgeInsets.all(20.0),
                                  child: Text(title, style: const TextStyle(color: Colors.white)),
                                ),
                          !full
                              ? Container(
                                  padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 20),
                                  decoration: BoxDecoration(
                                    color: Theme.of(context).scaffoldBackgroundColor,
                                    borderRadius: const BorderRadius.only(
                                      topLeft: Radius.circular(30.0),
                                      topRight: Radius.circular(30.0),
                                    ),
                                  ),
                                  child: ConstrainedBox(
                                    constraints: BoxConstraints(
                                      maxHeight: MediaQuery.of(context).size.height * ((maxHeight ?? 0.8) - 0.15) - MediaQuery.of(context).viewInsets.bottom,
                                    ),
                                    child: SingleChildScrollView(
                                      physics: const ScrollPhysics(parent: BouncingScrollPhysics()),
                                      child: Padding(
                                        padding: const EdgeInsets.only(bottom: 0),
                                        child: Column(
                                          crossAxisAlignment: CrossAxisAlignment.start,
                                          children: <Widget>[
                                            Divider(
                                              thickness: 2,
                                              indent: MediaQuery.of(context).size.width * 0.35,
                                              endIndent: MediaQuery.of(context).size.width * 0.35,
                                            ),
                                            child ?? const SizedBox(),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                )
                              : Expanded(
                                  child: Container(
                                    padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 20),
                                    decoration: BoxDecoration(
                                      color: Theme.of(context).scaffoldBackgroundColor,
                                      borderRadius: const BorderRadius.only(
                                        topLeft: Radius.circular(30.0),
                                        topRight: Radius.circular(30.0),
                                      ),
                                    ),
                                    child: ConstrainedBox(
                                      constraints: BoxConstraints(
                                        maxHeight: MediaQuery.of(context).size.height * ((maxHeight ?? 0.8) - 0.15) - MediaQuery.of(context).viewInsets.bottom,
                                      ),
                                      child: customChild ??
                                          SingleChildScrollView(
                                            physics: const ScrollPhysics(parent: BouncingScrollPhysics()),
                                            child: Padding(
                                              padding: const EdgeInsets.only(bottom: 0),
                                              child: Column(
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                children: <Widget>[
                                                  Divider(
                                                    thickness: 2,
                                                    indent: MediaQuery.of(context).size.width * 0.35,
                                                    endIndent: MediaQuery.of(context).size.width * 0.35,
                                                  ),
                                                  child ?? const SizedBox(),
                                                ],
                                              ),
                                            ),
                                          ),
                                    ),
                                  ),
                                ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    ),
  );
}