如何在Flutter Vcard中添加照片/徽标

huangapple go评论75阅读模式
英文:

How to add photo/logo in Flutter Vcard

问题

我正在设计一个新的数字名片,包括姓名、电话、地址等等。当我们扫描时,它会生成二维码,将所有的详细信息导入到手机设备,但我无法上传照片/标志。如何将上传的照片合并到vCard中,请指导和建议,我是Flutter的新手。

我想生成包含vCard详细信息的二维码。一切都运行正常,但在导入上传的图像时遇到问题,当我扫描二维码时,所有详细信息都会通过vCard插件直接导入到联系人,但我无法通过vCard从二维码中导入图像。

谢谢。

英文:

I am designing a new Digital vcard, Name, phone, address etc. it generate Qrcode when we scan that all the details is import to mobile phone device but i am not able to upload photo/ logo. how can I merge uploaded photo to vCard. Please guide and suggest I am new to Flutter.

I want to generate QRcode with vcard details. everything is working fine but facing issues to import uploaded image, when I scan QRcode all the details are directly import to contact with help of Vcard plugin. but I failed to import image from QR code via vcard.

Thank you

答案1

得分: 0

为了分享生成的二维码,请添加path_providerscreenshot包。

// 为截图定义一个控制器
ScreenshotController controller = ScreenshotController();

// 使用 Screenshot 包装你的 QrImageView
Screenshot(
  controller: controller,
  child: QrImageView(
    data: data,
    foregroundColor: foregroundColor,
    backgroundColor: backgroundColor,
    padding: EdgeInsets.all(padding),
    embeddedImage: image,
    eyeStyle: QrEyeStyle(
      eyeShape: eyeShape,
      color: foregroundColor,
    ),
    dataModuleStyle: QrDataModuleStyle(
      dataModuleShape: dataModuleShape,
      color: foregroundColor,
    ),
  ),
),

// 现在,在按钮点击时
IconButton(
  onPressed: () async {
    final list = await controller.capture();
    // controller.capture() 将捕获包装在 Screenshot() 中的部件
    if (list != null) {
      final directory = (await getTemporaryDirectory()).path;
      File imgFile = File(
          '$directory/${DateTime.now().millisecondsSinceEpoch}.png');
      imgFile.writeAsBytesSync(list);

      // 忽略:deprecated_member_use
      await Share.shareFiles(
        [imgFile.path],
        text: 'hi this is the text',
      ).catchError((e) {
        debugPrint('Error: $e');
      });
    }
  },
  icon: const Icon(Icons.send)
)

在Android中工作正常,但在iOS中一次只能分享文本或图像。

英文:

To share the generated qr code.
Add path_provider, screenshot packages

//Define a controller for screenshot

ScreenshotController controller = ScreenshotController();

//Wrap your QrImageView with Screenshot

Screenshot(
            controller: controller,
            child: QrImageView(
              data: data,
              foregroundColor: foregroundColor,
              backgroundColor: backgroundColor,
              padding: EdgeInsets.all(padding),
              embeddedImage: image,
              eyeStyle: QrEyeStyle(
                eyeShape: eyeShape,
                color: foregroundColor,
              ),
              dataModuleStyle: QrDataModuleStyle(
                dataModuleShape: dataModuleShape,
                color: foregroundColor,
              ),
            ),
          ),

//Now on click of a button

 IconButton(
          onPressed: () async {
            final list = await controller.capture();
            //controller.capture() will capture the widgets wrapped inside Screenshot()
            if (list != null) {
              final directory = (await getTemporaryDirectory()).path;
              File imgFile = File(
                  '$directory/${DateTime.now().millisecondsSinceEpoch}.png');
              imgFile.writeAsBytesSync(list);

              // ignore: deprecated_member_use
              await Share.shareFiles(
                [imgFile.path],
                text: 'hi this is the text',
              ).catchError((e) {
                debugPrint('Error: $e');
              });
            }
          },
          icon: const Icon(Icons.send))

//working in android but in ios only text or image can be share at one time

huangapple
  • 本文由 发表于 2023年2月27日 14:53:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577471.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定