0
votes

I'm trying to put a pop or even an alertedialog to announce that the message is sent or not.

Currently I only have a print that displays but in the console .. So not useful for the user.

How do I get to my goal?

  sendMail() async {
    // Information connexion serveur smtp
    String username = 'xxx';
    String password = 'xxxx';
    String domainSmtp = 'xxx';

    final smtpServer = SmtpServer(domainSmtp,
        username: username, password: password, port: 587);

    //Création du message
    final message = Message()
      ..from = Address(username, '')
      ..recipients.add('xxxx')

      //..ccRecipients.addAll(['[email protected]', '[email protected]'])
      //..bccRecipients.add(Address('[email protected]'))
      ..subject =
          "Demande :: ???? :: ${DateTime.now()}"
      ..text = ''
      ..html =
          "<h1>Nom: ${nomController.text} <p></p> Prénom: ${prenomController.text} <p></p> Email: ${emailController.text}</h1> <img src=\"data:images/Logo_fini2.1.png>  \n<p></p>";

    try {
      final sendReport2 = await send(message, smtpServer);
      var connection = PersistentConnection(smtpServer);
      await connection.send(message);
      await connection.close();
      print('Message envoyé: ' + sendReport2.toString());
    } on MailerException catch (e) {
      print('cMessage envoyé.');
      for (var p in e.problems) {
        print('Probleme: ${p.code}: ${p.msg}');
      }
    }
  }
}
2

2 Answers

0
votes

Use a snackbar or a AlertDialog

More info on snackbar :https://flutter.dev/docs/cookbook/design/snackbars

0
votes

I managed to solve my problem with fluttertoast. https://pub.dev/packages/fluttertoast

At the moment I am looking to add an icon .. If you had an idea I am a taker.

try {
  final sendReport2 = await send(message, smtpServer);
  print('Message envoyé: ' + sendReport2.toString());
  Fluttertoast.showToast(
      msg: "Demande envoyé avec succes",
      toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.BOTTOM,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.green,
      textColor: Colors.white,
      fontSize: 16.0);
} on MailerException catch (e) {
  print('cMessage envoyé.');
  for (var p in e.problems) {
    Fluttertoast.showToast(
        msg: "Erreur",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
        backgroundColor: Colors.red,
        textColor: Colors.white,
        fontSize: 16.0);
    print('Probleme: ${p.code}: ${p.msg}');
  }
}