Hello i would like to ask, is there a way to resolve this platform exption while picking files from google drive
I/flutter ( 2761): Error while picking file: PlatformException(unknown_path, Failed to retrieve path., null, null)
class _FilePickerScreenState extends State<FilePickerScreen> {
File? _pickedFile;
void _pickFile() async {
try {
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
setState(() {
_pickedFile = File(result.files.single.path!);
});
}
} on PlatformException catch (e) {
print('Error while picking file: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('File Picker Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _pickFile,
child: Text('Pick File'),
),
SizedBox(height: 20),
if (_pickedFile != null)
Text(
'Selected File: ${_pickedFile!.path.split('/').last}',
style: TextStyle(fontSize: 16),
),
],
),
),
);
}
}
2
Answers
Make this change in your code it will work
try this code
added on AndroidMenifest file