showAlert function

void showAlert({
  1. BuildContext? context,
  2. String? title,
  3. required Widget content,
  4. List<Widget>? actions,
  5. EdgeInsetsGeometry? titleBoxPadding,
  6. EdgeInsetsGeometry? titlePadding,
  7. EdgeInsetsGeometry? contentPadding,
  8. Color? titleColor,
  9. Color? titleBorderColor,
  10. Color? backgroundColor,
  11. double? titleBorderSize,
})

Implementation

void showAlert({
  BuildContext? context,
  String? title,
  required Widget content,
  List<Widget>? actions,
  EdgeInsetsGeometry? titleBoxPadding,
  EdgeInsetsGeometry? titlePadding,
  EdgeInsetsGeometry? contentPadding,
  Color? titleColor,
  Color? titleBorderColor,
  Color? backgroundColor,
  double? titleBorderSize,
}) {
  if (context == null && (!state.isContextLoaded || !state.appContext.mounted)) {
    assert(false,
    "App Context was not loaded or not mounted");

    return;
  }
  if (context != null && !context.mounted) {
    assert(false,
    "Provided Context was not loaded or not mounted");

    return;
  }
  context = context?? state.appContext;

  Widget? titleWidget;

  if (title != null && title.isNotEmpty) {
    titleWidget = Column(
      children: [
        Row(
          children: [
            Padding(
              padding: titlePadding?? const EdgeInsets.all(0),
              child: Text(
                  style: TextStyle(
                    color: titleColor,
                  ),
                  title
              ),
            ),
          ],
        ),
        Divider(
          thickness: titleBorderSize?? 1,
          color: titleBorderColor?? Colors.transparent,
        )
      ],
    );
  }

  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: titleWidget,
        content: content,
        actions: actions,
        titlePadding: titleBoxPadding,
        contentPadding: contentPadding,
        backgroundColor: backgroundColor,
      );
    },
  );
}