showSheetWidget<T> static method

Future<T?> showSheetWidget<T>(
  1. BuildContext context, {
  2. required WidgetBuilder builder,
  3. ModalPosition position = ModalPosition.bottom,
  4. dynamic barrierDismissible = true,
})

从底部弹出Widget

Implementation

static Future<T?> showSheetWidget<T>(
  BuildContext context, {
  required WidgetBuilder builder,
  ModalPosition position = ModalPosition.bottom,
  barrierDismissible = true,
}) async {
  return await showGeneralDialog<T?>(
      context: context,
      barrierColor: Colors.black12,
      useRootNavigator: true,
      barrierDismissible: barrierDismissible,
      barrierLabel: "",
      transitionDuration: const Duration(milliseconds: 300),
      pageBuilder: (BuildContext context, Animation<double> animation1,
          Animation<double> animation2) {
        const begin = Offset(0.0, 1.0);
        const end = Offset.zero;
        const curve = Curves.easeOut;

        var tween =
            Tween(begin: begin, end: end).chain(CurveTween(curve: curve));

        return SlideTransition(
          position: animation1.drive(tween),
          child: Scaffold(
            backgroundColor: Colors.transparent,
            resizeToAvoidBottomInset: false,
            body: GestureDetector(
              onTap: barrierDismissible
                  ? () {
                      Navigator.of(context).pop();
                    }
                  : null,
              child: Container(
                color: Colors.transparent,
                alignment: position == ModalPosition.bottom
                    ? Alignment.bottomCenter
                    : Alignment.center,
                child: GestureDetector(onTap: () {}, child: builder(context),),
              ),
            ),
          ),
        );
      });
}