import 'package:flutter/material.dart';

class FunctionUtil {
  static BuildContext? dialogContext;

  //显示中间弹窗
  static void popDialog(BuildContext context, Widget widget) {
    showDialog(
        context: context,
        barrierDismissible: true,
        builder: (BuildContext context) {
          dialogContext = context;
          return widget;
        });
  }

  //显示中间弹窗 点击空白处 返回键不关闭
  static void popDialog2(BuildContext context, Widget widget) {
    showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          dialogContext = context;
          return WillPopScope(onWillPop: () async => false, child: widget);
        });
  }

  //显示底部弹窗
  static void bottomSheetDialog(BuildContext context, Widget widget) {
    showModalBottomSheet(
      backgroundColor: const Color(0x00FFFFFF),
      context: context,
      /* isDismissible: false,*/
      isScrollControlled: true,
      builder: (BuildContext context) {
        dialogContext = context;
        return widget;
      },
    );
  }

  //显示底部弹窗
  static void bottomNoSheetDialog(BuildContext context, Widget widget) {
    showModalBottomSheet(
        backgroundColor: Color(0x00FFFFFF),
        context: context,
        isDismissible: false,
        isScrollControlled: true,
        enableDrag: false,
        builder: (BuildContext context) {
          dialogContext = context;
          return WillPopScope(onWillPop: () async => false, child: widget);
        });
  }

  //返回上一级
  static void pop() {
    Navigator.pop(dialogContext!);
  }

  //push到下一级
  static Future push(BuildContext context, Widget widget) {
    return Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => widget,
      ),
    );
  }
}
