posixRelative function
This creates a relative path from from
to input
, the output being a
posix path on all platforms.
Implementation
String posixRelative(String input, {String from = ''}) {
final context = path.Context(style: path.Style.posix);
final rawInputPath = input;
final absInputPath = File(rawInputPath).absolute.path;
// By going through URI's we can make sure paths can go between drives in
// Windows.
final inputUri = path.toUri(absInputPath);
final posixAbsInputPath = context.fromUri(inputUri);
final tempUri = path.toUri(from);
final posixTempPath = context.fromUri(tempUri);
return context.relative(posixAbsInputPath, from: posixTempPath);
}