At the moment i build a chat similar in wahtsapp.
I would like upload some local files (pdf, txt, image...).
Like this:
I try to get the local files via path_provider.
But i dont get access to download folder.
My problem:
I don't know how i can access the dowload folder with path_provider.
See my code:
//load local files from download folder
_loadLocalFile() async {
//absoulute path to download file
var file = io.Directory('/storage/emulated/0/Download/')
.listSync(); //use your folder name insted of resume.
//console output -> []
//other try to get download folder
List<io.Directory>? documents = await getExternalStorageDirectories();
//console output -> [Directory: '/storage/emulated/0/Android/data/de.securebuy.securebuy/files', Directory: '/storage/1BEC-0908/Android/data/de.securebuy.securebuy/files']
print(documents.toString());
}
I also add to AndroidManifest following rules:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGEā/>
Anyone have a idea how i can build a function similar in image?
Is that possible?
Many thx
till now , pathprovider isn't going to let you in downloads file , so if you are on android you can just write the downloads directory , else using android_path_provider it is a null-safety package and you can accsess it via :var downloadsPath = await AndroidPathProvider.downloadsPath; , on ios you can get only the app directory cuase ios makes it's own file for every app thus we use 'pathprovider' with Directory appDocDir = await getApplicationDocumentsDirectory();
Update :
i see what you are trying to achieve and this is not what pathprovider pcakage is used for , you have to use file_picker , read thier docs , i thinks that this is what you need
Related
In Stack Overflow or other example, I found that from asset folder and from network I can play audio file easily.
But, There is no clear approach That I can play audio file from Application Storage or mobile device.
My Audio path is : String playebleFilePath = '/Users/noorhossain/Library/Developer/CoreSimulator/Devices/5C9813C4-7773-4013-B086-279DB8FCA64F/data/Containers/Data/Application/F905830C-C698-4FEB-80F1-FB386BE18882/Library/Application Support/VocalDatabaseAudio/word_audio_one/2.mp3'
final assetsAudioPlayer = AssetsAudioPlayer();
assetsAudioPlayer.open(
Audio.file(playebleFilePath),
);
How can I play Audio from this storage path ?
My error log says : plugin Exception, cannot find the file in this server.
Any solution ?
I think the exception is due to the fact that the file you are trying to play is not in the assets folder which will cause the plugin to throw an exception.
i have been using audioplayers plugin and for assets it actually has a prefix to the path that actually points to an "assets" folder, the assets folder should also be correctly referenced in the pubspec.yaml file...
then more importantly since it seems you want to use app directory, consider using something like:await audioPlayer .play(DeviceFileSource("directory/path to your song"));
just check out the getting started of the audioplayers library: [ [1]: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md][1]
I am creating a Flutter Desktop application for windows and I am trying to retrieve the application directory where the exe is located. I tried to use path_provider but can only get the Documents directory. Any help I would appreciate lots.
Use Platform.resolvedExecutable
(of dart:io).
I have tested it in Flutter/Windows and it works.
Strangely, Platform.executable returns null instead. I tell strangely because its type is String not nullable. This unexpected null value can cause crash or errors that are difficult to detect (but in the end Flutter desktop is not in the stable channel).
String dir = Directory.current.path;
print(dir);
Directory.current.path (in the dart:io package) returns the current working directory of the project folder (when developing) or the executable directory when running from a release build.
Try is package: path_provider
set this code in pubspec.yaml
dependencies:
path_provider: ^1.6.27 # get last Version From https://pub.dev/packages/path_provider/install
Code
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path; //C:\Users\USER_NAME\AppData\Local\Temp
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path; //C:\Users\USER_NAME\Documents
//Warning: on debug mode this code get location project but in release mode will get your location app correctly
String dir = Directory.current.path; // PATH_APP
I am using flutter_pdfview which is version ^1.0.0+10 to open a PDF file in flutter apps. When my app is in debug mode, there is no error. After I build the app the PDF file cannot open in apps. My app will crash and close suddenly. I have open the permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
How can solve this error?
First you need to create a proguard-rules.pro file at /android/app/ inside there write like this:
#Flutter Wrapper
-keep class com.shockwave.**
Then at /android/app/build.gradle add this:
buildTypes {
release {
signingConfig signingConfigs.release
**minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'**
}
}
I have this problem only on android but when the app is on production. To fix this I add the permission handler plugin and change the path. Also and very important was add the extension ".pdf" to file after download but before read.
final filename = url.substring(url.lastIndexOf("/") + 1);
var request = await HttpClient().getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getExternalStorageDirectory()).path;
File file = new File('$dir/$filename.pdf');
await file.writeAsBytes(bytes);
pathPDF = file.path;
return file;
If you are running debug on an emulator and then release on a real device, this might be your problem:
PdfViewPage(path: '/storage/emulated/0/Download/$pdfName')));
Even if it isn't causing the crash it is a bad idea to hardcode download path like you've done. Different devices can have downloads in different locations. You can use downloads_path_provider to find where downloads is located.
Also, beside declaring the permissions needed in the Manifest you should also ask user for permission and handle the situation if the user doesn't give permission. For that task I suggest using permission_handler.
I am trying to find files located in assets. I have .txt, .gif, and .db files that are there in an eclipse android project but do not display when I run the following code:
AssetManager am = getAssets();
try {
String list[] = am.list("/");
I=0;
Str="";
while (list[] != null) {
Str=Str+"\r\n"+list[I];
I++;
}
}
catch(exception e){
}
I get this list:
AndroidManifest.xml
META-INF
assets
classes.dex
com
res
resources.arsc
This list does not include any of the files in assets.
Project properties is currently set to not include assets folder in the build path. When I do include the assets folder in the build path, it gives me the same list with ".." as the first file.
I have tried changing "/" in the third line to "/assets/" but get nothing returned.
Changing the Android Project Build Target between Android 2.3.1 and Android 2.1-update1 appears to have no effect.
Is there a setting in the project properties that is required for files in assets to be included in the build? Is there a different name for the assets directory using AssetManager?
list() takes a relative path within the assets. Seems in your case you need to pass an empty string, am.list("")
I am writing an Eclipse plugin where I want to read a file within the project and do something on it.
For example the file is located under : Project testplugin and path : com/flow/FlowMain.java
I want to programmatically read this file and add some code in it.
What I trying is :
String base = Platform.getBundle(config.getPluginId()).getEntry("/").toString();
String relativeUri = "com/flow/FlowMain.java";
File f = new File(base+relativeUri);
This obviously fails because the value of "base+relativeUri" returns :
entry://1079.fwk5184781/com/flow/FlowMain.java
So how do I go about getting the complete file path from within the plugin ?
'entry' is a protocol defined by equinox, so you can get the real path using org.eclipse.core.runtime.FileLocator.toFileURL(URL).
Use the below code to get the plugin path :
String workSpaceRootpath=this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()+Relativepath of a file;