mailto:Flutter for Web的链接

url_launcher软件包(https://pub.dev/packages/url_launcher)似乎不适用于Flutter for Web。以下代码显示“ test url1”,但此后什么也没发生。

如何在Flutter for Web中实现类似mailto:的功能,该功能导致默认电子邮件应用程序打开并带有预填充的“收件人:”电子邮件地址?

flatButton(
  onpressed: _mailto,//() => {},padding: EdgeInsets.all(3.0),child: _contactBtn(viewportConstraints),)


  _mailto() async {
    const url = 'mailto:support@email.com?subject=Product Inquiry&body=';
    print("test url1");
    if (await canLaunch(url)) {
      print("test url2");
      await launch(url);
    } else {
      print("test url3");
      throw 'Could not launch $url';
    }
  }
zcz888 回答:mailto:Flutter for Web的链接

import 'package:mailto/mailto.dart';

// For Flutter applications,you'll most likely want to use
// the url_launcher package.
import 'package:url_launcher/url_launcher.dart';

// ...somewhere in your Flutter app...
launchMailto() async {
    final mailtoLink = Mailto(
        to: ['to@example.com'],cc: ['cc1@example.com','cc2@example.com'],subject: 'mailto example subject',body: 'mailto example body',);
    // Convert the Mailto instance into a string.
    // Use either Dart's string interpolation
    // or the toString() method.
    await launch('$mailtoLink');
}
本文链接:https://www.f2er.com/3162102.html

大家都在问