【问题标题】:Flutter: Unable to display image in preview when image is shared Whatsapp and FacebookFlutter:在 Whatsapp 和 Facebook 共享图像时无法在预览中显示图像
【发布时间】:2018-12-10 09:05:51
【问题描述】:

图片可以在 Facebook Messenger 聊天中显示,但无法在 Whatsapp 中显示,也无法在 Messenger 和 whatsapp 中显示预览图。知道我哪里做错了吗?

Main.dart - 这是我捕获图像并将其保存到临时目录的位置。

  RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
  var image = await boundary.toImage(pixelRatio: 3.0);
  ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
  Uint8List pngBytes = byteData.buffer.asUint8List();

  final tempDir = await getTemporaryDirectory();
  final file = await new File('${tempDir.path}/image.png').create();
  await file.writeAsBytes(pngBytes);

  final channel = const MethodChannel('channel:me.amanda.share/share');
  channel.invokeMethod('shareFile', 'image.png'); 

MainActivity.java

private void shareFile(String path) {

try{
     File imageFile = new File(this.getCacheDir(), path);
     Uri contentUri = FileProvider.getUriForFile(this, "me.amanda.share", 
     imageFile);
     Intent shareIntent = new Intent(Intent.ACTION_SEND);
     shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     shareIntent.setData(contentUri);
     shareIntent.setType("image/png");

     shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
     this.startActivity(Intent.createChooser(shareIntent, "Share image 
     using"));
     }
     catch (Exception ex){
        //android.widget.Toast.makeText(this, ex.getMessage(), 
        Toast.LENGTH_SHORT).show();
     }
  }

file_path.xml

    <?xml version="1.0" encoding="utf-8"?>
    <paths>
    <cache-path name="image" path="."/>
    </paths>

【问题讨论】:

    标签: android image android-intent dart flutter


    【解决方案1】:

    对不起,这是一个非常愚蠢的错误。图像是二维码,二维码的背景是透明的。因此,我应该将 qr 图像包装到 Container() 小部件中,并将容器设置为白色,RepaintBoundary 可以使用 QR 码捕获整个容器。我没有注意到预览图像和信使是黑暗的。

    这是一个例子。

        hasValue ? Container(
        height: 230.0,
        color: Colors.white,
        margin: EdgeInsets.all(10.0),
        child: Center(
          child: RepaintBoundary(
            key: globalKey,
            child: Container(
              color: Colors.white,
              child: QrImage(
                data: !isScan ? _dataBarcodeString : trimBarcodeValue,
                size: 200.0,
              ),
            )
          ),
        ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-26
      • 2014-09-05
      • 1970-01-01
      • 2015-06-04
      • 1970-01-01
      • 2014-07-18
      • 2022-06-20
      • 1970-01-01
      相关资源
      最近更新 更多