Amani
Amani

Reputation: 18173

How can I convert a relative path to absolute path in Dart?

I have a Dart code that need to take a path and work on it. For portability purposes I need the path to be relative and have Dart convert it to absolute path. How can I do this. For example:

var samplePath = 'relative/path/file.txt';
// converted to 'C:/Users/XYZ/Desktop/relative/path/file.txt'

Upvotes: 4

Views: 2163

Answers (2)

shell3
shell3

Reputation: 71

Flutter 2.7

import 'package:path/path.dart' as p;

var absPath = p.absolute('a/b', 'c');
// '...<current working dir>/a/b/c

Documentation

Upvotes: 5

JLD
JLD

Reputation: 89

I have never programmed in Dart, but in this part of the documentation there is a property of the class File which does what you want.

Moreover, if you have the root path of your relative path (maybe your current directory) you can join them using the join function

Hope it helps you.

Upvotes: 0

Related Questions