【问题标题】:Generate VCF file through QR Code using flutter?使用flutter通过二维码生成VCF文件?
【发布时间】:2021-10-22 12:45:49
【问题描述】:

当其他用户扫描自己的二维码时,我想分享一个用户联系人。

场景:

用户想要分享他的联系人 另一个用户扫描他的二维码 最终用户有一个VCF文件来存储本地信息

这可能吗?

【问题讨论】:

    标签: flutter qr-code vcf-vcard


    【解决方案1】:

    要生成二维码,请使用qr_flutter

    要保存生成的二维码,请使用以下功能:

    Future<String> get _localPath async {
    final directory = await getApplicationDocumentsDirectory();
    return directory.path;
    }
    
    Future<File> get _localFile async {
    final path = await _localPath;
    return File('$path/contact.vcf');
    }
    
    Future<File> _createFile(String data) async {
    final file = await _localFile;
    return file.writeAsString(data);
    }
    

    你需要path_provider

    要分享二维码,请使用share

    IconButton(
            onPressed: () async {
              var _vcf = await _createFile(_data);
              await Share.shareFiles(
                [_vcf.path],
                subject: 'vCardName',
                text: 'vCard',
              );
            },
          icon: const Icon(Icons.share),
          )
    

    【讨论】: