1

I am trying to select a file using the File Picker package but it gives an error of Unable to load asset: /data/user/0/com.example.demo_app/cache/file_picker/sample1.txt

After selecting the file, I write code to make some implementattion of adding some quotation marks to it but the file won't even load

Below is the code for that:

String? fileResult;
  Text? zeroTurniton;
  PlatformFile? firstFile;
  pw.Document? pdf;
  Future<void> pickAndEditFile() async {
    FilePickerResult? files = await FilePicker.platform.pickFiles(
      allowedExtensions: ['doc', 'txt', 'docx'],
      type: FileType.custom,
      allowMultiple: false,
    );
    if (files == null) {
      return;
    } else {
      print('------------${firstFile?.name}----------');
      try {
        firstFile = files.files.first;
        String result;
        result = await rootBundle.loadString(firstFile!.path!);
        setState(() {
          fileResult = result;
        });
        Text quote = const Text(
          '"',
          style: TextStyle(color: Colors.white),
        );
        zeroTurniton = Text(quote.toString() + result + quote.toString());
      } catch (e) {
        print(e.toString()); //**Prints the error here**
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text(e.toString()),
            backgroundColor: Theme.of(context).errorColor,
          ),
        );
      }
    }
  }
Samuel
  • 472
  • 4
  • 14

1 Answers1

0

Okay so I just changed the File Picker package and it worked fine

Samuel
  • 472
  • 4
  • 14