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

[Question]: the class XFILE doesn't exist. #1271

Closed
7 tasks done
juliuskopp opened this issue Oct 19, 2022 · 5 comments · Fixed by #1286
Closed
7 tasks done

[Question]: the class XFILE doesn't exist. #1271

juliuskopp opened this issue Oct 19, 2022 · 5 comments · Fixed by #1286
Labels
question Further information is requested

Comments

@juliuskopp
Copy link

juliuskopp commented Oct 19, 2022

What is your question?

  1. I create a class and wanted to use "Share.shareXFiles".
  2. I add "import 'package:share_plus/share_plus.dart';"
  3. When writting this line : await Share.shareXFiles([XFile(filename)], I have this message : The method 'XFile' isn't defined for the type 'DataShareService'.
  4. So I have to add this import "import 'package:cross_file/cross_file.dart';"
  5. But now I have this message "package:cross_file/cross_file.dart Depend on referenced packages.dartdepend_on_referenced_packages"

In your example, you don't have the problem because XFile is referenced by this import : 'package:image_picker/image_picker.dart'

In the example below, I have commented the line of the import 'package:cross_file/cross_file.dart' so you can see the problem. If you uncomment the import 'package:cross_file/cross_file.dart'; you'll see the other message.
Thanks.

Code sample :

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
// TODO : uncomment the line below to refrence XFile
//import 'package:cross_file/cross_file.dart';

class DataShareService {
void sharingFile({
required String filename,
required BuildContext context,
required String subject,
}) async {

final box = context.findRenderObject() as RenderBox?;

await Share.shareXFiles([XFile(filename)],
    subject: subject,
    sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size);

}
}

Checklist before submitting a question

  • 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 am 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
@juliuskopp juliuskopp added the question Further information is requested label Oct 19, 2022
@miquelbeltran
Copy link
Member

But now I have this message "package:cross_file/cross_file.dart Depend on referenced packages.dartdepend_on_referenced_packages"

Do what the warning suggests and add the dependency to cross_file, which is an official package from the Flutter team.

@werainkhatri
Copy link
Contributor

werainkhatri commented Oct 22, 2022

Do what the warning suggests and add the dependency to cross_file, which is an official package from the Flutter team.

maybe share_plus should export the package? same as what image_picker does?

https://github.com/flutter/plugins/blob/f55c7ffc6984c75e6b2b6a72a02b48064e0b5bc1/packages/image_picker/image_picker_platform_interface/lib/image_picker_platform_interface.dart#L5

@miquelbeltran
Copy link
Member

Good point @werainkhatri a PR with the fix is more than welcome ;)

@werainkhatri
Copy link
Contributor

a PR with the fix is more than welcome

you got it!

@jingluoguo
Copy link

you can write import 'package:cross_file/cross_file.dart';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants