1

how do I create an email hyperlin in flutter? ////////////////////////////////////////////////////////////

import 'package:flutter/material.dart';


showAlertDialog(BuildContext context) {
  AlertDialog alert = const AlertDialog(
    title: Text('Contact us'),
    content: Text(
        'Please contact our team via email: **myemail@email.com**', //hyperlink
    ),
  );
  showDialog(
    context: context,
    builder: (BuildContext context){
      return alert;
    },
  );
}
Zero_Bolt
  • 87
  • 1
  • 9
  • Does this answer your question? [How do you open the default email app on an iPhone with Flutter?](https://stackoverflow.com/questions/51091785/how-do-you-open-the-default-email-app-on-an-iphone-with-flutter) – mkobuolys Feb 28 '22 at 23:22
  • Thanks for the tip, but in my case the hyperlink is in a text inside AlertDialog, I really don't know how to do it :( – Zero_Bolt Feb 28 '22 at 23:44

4 Answers4

2

Flutter natively support Rich text, but I think doesn't enough for you. You can use this package for your operations, and you can handle your link directly.(If you want you should be to write custom action for links for instance below code)

Widget html = Html(
  data: """<p>
   Linking to <a href='https://github.com'>websites</a> has never been easier.
  </p>""",
  onLinkTap: (String? url, RenderContext context, Map<String, String> attributes, dom.Element? element) {
    //open URL in webview, or launch URL in browser, or any other logic here
  }
);
vb10
  • 641
  • 5
  • 14
1

Use Package url_launcher:

 final Uri emailLaunchUri = Uri(
  scheme: 'StackOverFlow',
  path: 'https://stackoverflow.com',
  query: encodeQueryParameters(<String, String>{
    'subject': 'Example Subject & Symbols are allowed!'
  }),
);

launch(emailLaunchUri.toString());
Hammad Ali
  • 328
  • 2
  • 8
  • Could you show me how to use url_launcher in my code? because I couldn't insert the hyperlink only in the email. – Zero_Bolt Mar 03 '22 at 14:10
1

Simply, you can use this package to send email directly

email_launcher: ^1.1.1

  import 'package:email_launcher/email_launcher.dart';


Email email = Email(
    to: ['one@gmail.com,two@gmail.com'],
    cc: ['foo@gmail.com'],
    bcc: ['bar@gmail.com'],
    subject: 'subject',
    body: 'body'
);
await EmailLauncher.launch(email);
Anand
  • 4,355
  • 2
  • 35
  • 45
  • Could you show me how to use email_launcher in my code? because I couldn't insert the hyperlink only in the email. – Zero_Bolt Mar 03 '22 at 14:10
1
Uri emailLanuch = Uri(
    scheme: 'mailto',
    path: "myemail@email.com",
  );
  showAlertDialog(BuildContext context) {

    AlertDialog alert =AlertDialog(
      title: Text('Contact us'),
      content: ,
      actions: [
        TextButton(
          onPressed: () async {
            await launch(emailLanuch.toString());
          },
          child: Text("myemail@email.com"),
        ),
      ],
    );
    showDialog(
      context: context,
      builder: (BuildContext context){
        return alert;
      },
    );
  }
Hammad Ali
  • 328
  • 2
  • 8