Skip to content

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

@juliuskopp

Description

@juliuskopp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions