showText function

Future<bool> showText(
  1. BuildContext context,
  2. String title,
  3. String subtitle, {
  4. bool isNotification = false,
  5. bool isFlash = true,
  6. int seconds = 5,
  7. Color? backgroundColor,
  8. Widget? leading,
  9. Widget? titleMessage,
  10. Widget? subtitleMessage,
  11. Widget? closeTextDialog,
  12. List<Widget>? trailing,
  13. Function? onTap,
})

Information dialog Shows a flash dialog or a simple dialog with @isFlash = false

Implementation

Future<bool> showText(
  BuildContext context,
  String title,
  String subtitle, {
  bool isNotification = false,
  bool isFlash = true,
  int seconds = 5,
  Color? backgroundColor,
  Widget? leading,
  Widget? titleMessage,
  Widget? subtitleMessage,
  Widget? closeTextDialog,
  List<Widget>? trailing,
  Function? onTap,
}) async {
  try {
    if (isFlash) {
      return (await showFlash(
            context: context,
            duration: Duration(seconds: seconds),
            transitionDuration: Duration(seconds: isNotification ? 2 : 1),
            builder: (context, controller) {
              return Flash(
                forwardAnimationCurve: Curves.elasticInOut,
                reverseAnimationCurve: Curves.elasticInOut,
                controller: controller,
                position: FlashPosition.bottom,
                child: GestureDetector(
                  onTap: () {
                    if (onTap != null) onTap();
                  },
                  child: FlashBar(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(
                            Radius.circular(!isNotification ? 0 : 20))),
                    margin: !isNotification
                        ? EdgeInsets.zero
                        : const EdgeInsets.all(20),
                    shouldIconPulse: false,
                    icon: SizedBox(height: 30, width: 30, child: leading),
                    actions: trailing,
                    backgroundColor: backgroundColor ?? Colors.blue[800],
                    title: titleMessage ??
                        Text(
                          title,
                          style: const TextStyle(
                              color: Colors.white, fontSize: 20),
                        ),
                    content: subtitleMessage ??
                        Text(
                          subtitle,
                          style: const TextStyle(
                              color: Colors.white70, fontSize: 16),
                        ),
                    controller: controller,
                  ),
                ),
              );
            },
          ) as bool?) ??
          false;
    } else {
      return await showDialog<bool>(
              context: context,
              barrierDismissible: true,
              builder: (BuildContext context) {
                return SimpleDialog(
                  shape: const RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(Radius.circular(20))),
                  children: <Widget>[
                    Padding(
                      padding: const EdgeInsets.all(20.0),
                      child: titleMessage ??
                          Text(
                            title,
                            style: TextStyle(
                                color: Colors.green[900], fontSize: 25),
                          ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(15.0),
                      child: subtitleMessage ??
                          Text(
                            subtitle,
                            style: TextStyle(
                                color: Colors.brown[900], fontSize: 15),
                          ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(30.0),
                      child: ElevatedButton(
                        onPressed: () {
                          Navigator.of(context).pop();
                        },
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: closeTextDialog ??
                              const Text(
                                "OK",
                                style: TextStyle(
                                    color: Colors.white, fontSize: 18),
                              ),
                        ),
                      ),
                    ),
                  ],
                );
              }) ??
          false;
    }
  } catch (err) {
    if (kDebugMode) {
      print(err);
    }
    return false;
  }
}