I'm currently using the path_provider
package for the initialisation of Hive
in my main.dart
:
final appDocumentDirectory = await pathProvider.getApplicationDocumentsDirectory();
Hive.init(appDocumentDirectory.path);
I want to embed a local database file from my assets folder and followed a Youtube Tutorial (Link) in which he was using the path
package for 'joining' the databasePath with the database file. Here's the code:
_db = await openDatabase('assets/trails.db');
var databasePath = await getDatabasesPath();
var path = join(databasePath,'trails.db');
The docs are saying:
path
: The path package provides common operations for manipulating paths: joining, splitting, normalizing, etc.path_provider
: A Flutter plugin for finding commonly used locations on the filesystem.But my question now is, what exactly is the difference between these two packages? Would it be possible for me to delete one of them of my pubspec.yaml
file and use one package for both use-cases (to avoid boilerplate code)?
I think the answer is no.
path
is a package to manipulate paths: join them, convert to absolute, add prefixes, get path info and so on.
path_provider
is dedicated to more specific OS operations, e.g. downloads, temporary files, application documents are stored in different places based on the OS (obviously, file structure in Android is different than in iOS, Windows, Linux, etc.).
To compare these two, packages have different purpose - path
to actually "work" with paths while path_provider
, well, provide you with the exact path to resources based on OS. Hence, you cannot replace one with the other, if you need to use both, that's it, just use both of them.