【发布时间】:2021-05-24 16:37:41
【问题描述】:
我正在尝试使用带有 social_share 包的颤振在 Instagram 上发送图像。
我的问题是我是 Flutter 的新手,我找不到正确的方法来发送函数 SocialShare.shareInstagramStory(imageFile.path, "#ffffff", "#000000", "https://deep-link-url"); 的路径
我的图片位于 flutter 项目的根目录 assets/images/my_images。
当我尝试把路径SocialShare.shareInstagramStory("assets/images/my_image.jpeg");
我猜手机不知道这条路径,因为它正在查看他自己的目录
希望我足够清楚,感谢您的时间!
编辑:这是我的代码:
onPressed: () async {
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
File file = File(tempDir.path);
final byteData = await rootBundle.load('assets/images/img_1.jpeg');
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
await SocialShare.shareInstagramStory(file.path);
Navigator.of(context).pop();
},
我收到了这个错误:
E/flutter (12761): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: FileSystemException: Cannot open file, path = '/data/user/0/com.example.app/cache' (OS Error: Is a directory, errno = 21)
【问题讨论】:
-
2 things.1> 您是否在 pubspec 中声明了此图像文件。 yaml。 2> 你有没有停止然后重新启动应用程序?热重启不会这样做。如果您不知道第一个,请告诉我。我会在我的回答中详细说明
-
感谢您的回答!是的,我都做了!