Saving files locally so available to email or view in file manager Android
You are using the path_provider
package and The getApplicationDocumentsDirectory
returns the path to the applications hidden directory. Users can't see this directory with file managers (There is a way to find it but that is not easy for end user).
You can use the downloads_path_provider
package:
import 'package:downloads_path_provider/downloads_path_provider.dart';
Future<Directory> downloadsDirectory = DownloadsPathProvider.downloadsDirectory;
In this code, the downloadsDirectory
is the Downloads directory in phone storage, that can be seen by user. Then you can open or email it.
downloads_path_provider package link
user2244131
Hi, I'm a maths teacher and used to be a java developer. My aim is to develop a maths application that teaches how to understand any maths topic. To begin with I'm starting with factors and then will extend this over many years. I hope I can help others as well as others helping me to understand android. In my past I developed SQL Server databases, java, C++, VB etc My knowledge of java is good, but my knowledge of android is poor, at present. Thanks to all who help, what comes round, goes round.
Updated on December 15, 2022Comments
-
user2244131 over 1 year
Flutter, dart and Visual Studio. Android Devices.
After saving a file and reading it back to ensure all went OK I can't find the file, so it can't be emailed or viewed at all.
How can I save it so the user can see the file, so they can read it, or email it etc.
Thanks
class SaveJson { SaveJson(); Future<String> get _localPath async { final directory = await getApplicationDocumentsDirectory(); return directory.path; } Future<File> get _localFile async { final path = await _localPath; final file = File('${path}/macf.txt'); return file; } Future<File> writeJson(String data) async { final file = await _localFile; return file.writeAsString(data); } read() async { try { final directory = await getApplicationDocumentsDirectory(); final file = File('${directory.path}/macf.txt'); String text = await file.readAsString(); print(text); } catch (e) { print("Couldn't read file"); } } }