Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: share_plus on windows does not attach file instead it attach file path #3089

Open
8 tasks done
richard457 opened this issue Jul 13, 2024 · 1 comment
Open
8 tasks done
Labels
bug Something isn't working triage

Comments

@richard457
Copy link

Platform

Windows 11

Plugin

share_plus

Version

share_plus: ^9.0.0

Flutter SDK

3.22

Steps to reproduce

Future shareFileAsAttachment(String filePath) async {
final now = DateTime.now();
final formattedDate = DateFormat('yyyy-MM-dd').format(now);
final file = File(filePath);
final fileName = p.basename(file.path);

if (Platform.isWindows || Platform.isLinux) {
  final bytes = await file.readAsBytes();
  final mimeType = _lookupMimeType(filePath);
  await Share.shareXFiles(
    [XFile.fromData(bytes, mimeType: mimeType, name: fileName)],
    subject: 'Report Download - $formattedDate',
  );
} else {
  await Share.shareXFiles(
    [XFile(filePath)],
    subject: 'Report Download - $formattedDate',
  );
}

}

Code Sample

Future<void> shareFileAsAttachment(String filePath) async {
    final now = DateTime.now();
    final formattedDate = DateFormat('yyyy-MM-dd').format(now);
    final file = File(filePath);
    final fileName = p.basename(file.path);

    if (Platform.isWindows || Platform.isLinux) {
      final bytes = await file.readAsBytes();
      final mimeType = _lookupMimeType(filePath);
      await Share.shareXFiles(
        [XFile.fromData(bytes, mimeType: mimeType, name: fileName)],
        subject: 'Report Download - $formattedDate',
      );
    } else {
      await Share.shareXFiles(
        [XFile(filePath)],
        subject: 'Report Download - $formattedDate',
      );
    }
  }

Logs

N/A

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.4.1 23E224 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] IntelliJ IDEA Community Edition (version 2024.1.1)
[✓] VS Code (version 1.88.1)
[✓] Connected device (2 available)
[✓] Network resources

Checklist before submitting a bug

  • I searched issues in this repository and couldn't find such bug/problem
  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
@richard457 richard457 added bug Something isn't working triage labels Jul 13, 2024
@miquelbeltran
Copy link
Member

Hello, I have no idea, honestly, but a couple of things to consider nevertheless:

  1. Avoid using XFile.fromData and instead write down the file in a folder you control. This shold be mentioned in the README.md file. The name parameter in XFile does nothing, only works on web, this is a known issue in the XFile dart package.
  2. shareXFile() doesn't work at all on Linux. Also mentioned on the README file. Saying this because you have || Platform.isLinux in the example code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants