Resolve Tilde
Resolve Tilde is a quick and easy package to, well, resolve tildes. Tildes are the wavy symbols (~) that Dart can't naturally expand.
Notes
- This package is in beta and has not yet been universally tested.
Platform Support
| Platform | Supported | Notes |
|---|---|---|
| Windows | β | Supported as of version 0.0.0 |
| macOS | β | Supported as of version 0.0.0 |
| Linux | β | Supported as of version 0.0.0 |
| Android | π₯ | Unsupported due to restricted filesystem |
| iOS | π₯ | Unsupported due to restricted filesystem |
| Web | π₯ | Unsupported due to no filesystem |
Layout
Constants
tilde: This is defined in the top level, so if the package is imported, you can simply referencetildeto get~as aString.Tilde.tilde: This is the exact same thing as the above constant, except it's a static member of theTildeclass.
Classes
Tilde: This is the main class for containing resources for resolving tildes.
- Static constant
Tilde.tilde: Discussed above. - Static
StringfunctionTilde.resolve: This function is what actually resolves the tildes.- You can pass an optional positional
pathparameter to specify the path to actually expand. The default is just a tilde. - Note that this function does not fully expand the path; it only expands the first tilde in the included path if that tilde is at the beginning of the path.
- You can pass an optional positional
- Static
StringfunctionTilde.resolveOrNull: This function is the same asTilde.resolve, but if aHomeDirectoryNotFoundExceptionis thrown, then this function will catch it and return null. This would be generally better for safety, if you're fine with null checks.
Usage
Constants
import 'package:resolve_tilde/resolve_tilde.dart';
print(tilde); // Output: '~'
print(Tilde.tilde); // Output: '~'
Resolving
import 'package:resolve_tilde/resolve_tilde.dart';
if (Platform.isWindows) {
print(Tilde.resolve()); // Output: 'C:\Users\user' or similar
print(Tilde.resolveOrNull() ?? "No home dir found"); // Output: 'C:\Users\user', similar, or null
print(Tilde.resolve("~\\AppData\\Local")); // Output: 'C:\Users\user\AppData\Local'
} else if (Platform.isMacOS || Platform.isLinux) {
print(Tilde.resolve()); // Output: '/home/user' or similar
print(Tilde.resolveOrNull() ?? "No home dir found"); // Output: '/home/user', similar, or null
print(Tilde.resolve("~/Pictures/Screenshots")); // Output: '/home/user/Pictures/Screenshots' or similar
}
Libraries
- resolve_tilde
- Support for resolve_tilde.