showAlertDialog function

Future<bool> showAlertDialog(
  1. BuildContext? context,
  2. String title,
  3. String content,
  4. List<Widget> actions, {
  5. TextStyle? titleStyle,
  6. TextStyle? contentStyle,
  7. MainAxisAlignment? actionsAlignment,
  8. Color? backgroundColor,
  9. Brightness? backgroundBrightness,
})

Implementation

Future<bool> showAlertDialog(
  BuildContext? context,
  String title,
  String content,
  List<Widget> actions, {
  TextStyle? titleStyle,
  TextStyle? contentStyle,
  MainAxisAlignment? actionsAlignment,
  Color? backgroundColor,
  Brightness? backgroundBrightness,
}) async {
  if (!(context?.mounted ?? false)) {
    ZegoLoggerService.logInfo(
      'show dialog error, context is not mounted, '
      'context:$context, '
      'title:$title, '
      'content:$content, '
      'actions:$actions, ',
      tag: 'uikit',
      subTag: 'dialogs',
    );

    return false;
  }

  var result = false;

  try {
    result = await showDialog(
          context: context!,
          barrierDismissible: false,
          builder: (BuildContext context) {
            return CupertinoTheme(
              data: CupertinoThemeData(
                brightness: backgroundBrightness ?? Brightness.dark,
              ),
              child: CupertinoAlertDialog(
                title: Text(
                  title,
                  textAlign: TextAlign.center,
                  style: titleStyle ??
                      TextStyle(
                        fontSize: 30.0.zR,
                        fontWeight: FontWeight.bold,
                        color: const Color(0xff2A2A2A),
                      ),
                ),
                content: Text(
                  content,
                  textAlign: TextAlign.center,
                  style: contentStyle ??
                      TextStyle(
                        fontSize: 28.0.zR,
                        color: const Color(0xff2A2A2A),
                      ),
                ),
                actions: actions,
              ),
            );
          },
        ) ??
        false;
  } catch (e) {
    ZegoLoggerService.logError(
      'show dialog error, $e, '
      'context;$context, ',
      tag: 'uikit',
      subTag: 'dialogs',
    );
  }

  return result;
}