file_picker allowedExtensions filter dosent work
Asked Answered
G

1

9

i using extention file_picker in flutter width extention filter

try {
      result = await FilePicker.platform.pickFiles(
        type: FileType.custom,
        allowedExtensions: ['jpeg', 'jpg', 'heic', 'pdf'],
      );
    } catch (e) {
      print('fileSelector ****${e}***');
    }

but in Android i can select all files width any extension. In IOS work this filter fine. Is it a bug in file_picker or do I have to do something additional?

Golter answered 22/6, 2021 at 11:39 Comment(1)
Maybe this can help: github.com/miguelpruivo/flutter_file_picker/wiki/FAQPartheniaparthenocarpy
O
1
onPressed: () async {
                              String? outputFile =
                                  await FilePicker.platform.saveFile(
                                allowedExtensions: null,
                                type: FileType.any,
                                dialogTitle:
                                    'Please select an output file:',
                                fileName: 'show',
                              );

                              if (outputFile == null) return;

                              if (!outputFile.endsWith('.pdf')) {
                                outputFile = '$outputFile.pdf';
                              }
                             
                            },

Just put a custom check if the outputFile doesn't have it.

Odd answered 11/4 at 10:7 Comment(1)
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?Morley

© 2022 - 2024 — McMap. All rights reserved.