showAlert function

Future<bool?> showAlert(
  1. BuildContext context, {
  2. required String message,
  3. required String id,
  4. String? title,
  5. Widget? child,
  6. String buttonMsg = '确认',
})

Implementation

Future<bool?> showAlert(
  BuildContext context, {
  required String message,
  required String id,
  String? title,
  Widget? child,
  String buttonMsg = '确认',
}) async {
  if (showAlertId[id] == null) {
    showAlertId[id] = id;
    final bool? res = await showModalBottomSheet(
      context: context,
      backgroundColor: Colors.transparent,
      useRootNavigator: true,
      builder: (BuildContext context) {
        return Column(
          mainAxisAlignment: MainAxisAlignment.end,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Container(
              width: MediaQuery.of(context).size.width * 0.75,
              decoration: const BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10),
                  topRight: Radius.circular(10),
                ),
              ),
              padding: EdgeInsets.all(20.r),
              child: Column(
                children: [
                  SizedBox(height: 12.r),
                  if (title != null)
                    Text(
                      title,
                      style: TextStyle(
                        fontSize: 36.r,
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                  if (title != null) const SizedBox(height: 20),
                  Text(
                    message,
                    style: TextStyle(fontSize: 28.r, color: Colors.black),
                  ),
                  if (child != null) Container(child: child),
                  SizedBox(height: 30.r),
                  SizedBox(
                    width: 480.r,
                    child: BaseButton(
                      fontSize: 32.r,
                      onPressed: () {
                        Navigator.of(context).pop(true);
                      },
                      borderRadius: 99.r,
                      text: buttonMsg,
                    ),
                  ),
                  SizedBox(height: 32.r),
                ],
              ),
            ),
            BaseBottomPadding(),
          ],
        );
      },
    );
    showAlertId.remove(id);
    return res;
  }
  return null;
}