As I understand it, you want to save any file from url in the data folder of the application and read it.
First you need to install the path_provider and http packages.
open terminal and run scripts:
flutter pub add path_provider
flutter pub add http
Let's add the files to the beginning of the file.
import 'dart:io';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:http/http.dart' show get;
Now let's write the download and save code:
Future<bool> yourMethodName(String downloadUrl) async {
var url = Uri.parse(downloadUrl);
var response = await get(url);
var documentDirectory = await getApplicationDocumentsDirectory();
// yourDirectoryName or assets...
var yourPath = "${documentDirectory.path}/yourDirectoryName";
var filePathAndName = '$yourPath/fileName.jpg';
await Directory(yourPath).create(recursive: true);
File yourFile = File(filePathAndName);
yourFile.writeAsBytesSync(response.bodyBytes);
return true;
}
Call from within any function
callFunction()async{
await yourMethodName('http://example.com/image.jpg'); // Or pdf,or etc.
}
There is a different approach for each file. If you give more detailed information, I can help you with the reading. For example I want to read picture or pdf.
If you have any questions don't hesitate to ask.