In the below code of flutter_material_pickers plugin, I want to get the video file path but the returned file variable of showMaterialFilePicker function is Uint8List type.
void onTap() {
if (value == null) {
showMaterialFilePicker(
fileType: Filetype.video,
onChanged: (file) => setState(() {
didChange(file);
if (widget.onChanged != null) widget.onChanged(file);
}),
);
} else {
_showUnattachDialog();
}
}
Refer to this function of flutter_material_pickers, The code is:
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// Allows selection of a file.
Future<void> showMaterialFilePicker({
BuildContext context,
FileType fileType = FileType.image,
String fileExtension,
ValueChanged<Uint8List> onChanged,
}) async {
try {
File file = await FilePicker.getFile(type: fileType);
var data = file.readAsBytesSync();
if (onChanged != null && file != null) onChanged(data);
} catch (error) {
if (error.runtimeType is PlatformException) return; // user clicked twice
if (error.runtimeType is NoSuchMethodError) return; // user canceled dialog
throw error;
}
}
No, there is no option to read path from Uint8List
. This type stores only byte data. You can even test it by comparing results of readAsBytes()
from two equal images in different locations.
You can use file_picker (this package is used in flutter_material_pickers as well) and get File
as in Usage section and from File
you have access to the path.