notificationDialog function

dynamic notificationDialog(
  1. BuildContext buildContext,
  2. String title,
  3. String message, {
  4. Function? onTap,
  5. String? path,
  6. Color? backgroundColor,
})

Notification dialog Shows a notification dialog with given title and message

Implementation

notificationDialog(BuildContext buildContext, String title, String message,
    {Function? onTap, String? path, Color? backgroundColor}) async {
  try {
    if (kDebugMode) {
      print(path);
    }
    showFlash(
      context: buildContext,
      duration: const Duration(seconds: 5),
      builder: (context, controller) {
        return Flash(
          controller: controller,
          position: FlashPosition.bottom,
          child: GestureDetector(
            onTap: () {
              if (onTap != null) onTap();
            },
            child: FlashBar(
              shape: const RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(20))),
              behavior: FlashBehavior.floating,
              margin: const EdgeInsets.all(20),
              backgroundColor: backgroundColor ?? Colors.blue[800],
              title: Text(
                title,
                style: const TextStyle(color: Colors.white, fontSize: 25),
              ),
              content: Text(
                message,
                style: const TextStyle(color: Colors.white70, fontSize: 20),
              ),
              controller: controller,
            ),
          ),
        );
      },
    );
  } catch (err) {
    if (kDebugMode) {
      print(err);
    }
    return showDialog<bool>(
      context: buildContext,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return SimpleDialog(
          title: Text(title),
          shape: const RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(20))),
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(15.0),
              child: Text(
                message,
                style: TextStyle(color: Colors.blueGrey[600], fontSize: 15),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Padding(
                  padding: const EdgeInsets.all(10.0),
                  child: Card(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(20)),
                    color: Colors.blue[800],
                    child: TextButton(
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                      child: const Padding(
                        padding: EdgeInsets.all(8.0),
                        child: Text(
                          "OK",
                          style: TextStyle(color: Colors.white, fontSize: 18),
                        ),
                      ),
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(10.0),
                  child: Card(
                    color: Colors.green[700],
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(20)),
                    child: TextButton(
                      onPressed: () {
                        if (onTap != null) onTap();
                      },
                      child: const Padding(
                        padding: EdgeInsets.all(8.0),
                        child: Text(
                          "Go",
                          style: TextStyle(color: Colors.white, fontSize: 18),
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        );
      },
    );
  }
}