isolate_current_directory library
Dart's Directory.current can be set to change the current directory, but this is a true global variable shared even between different Isolates.
That makes it almost impossible to write Dart code that requires changing the current working directory while using more than one Isolate, as changes in one Isolate would affect all Isolates.
This library solves that problem by providing a function,
withCurrentDirectory()
, which effectively changes Directory.current only
in the current Isolate.
It relies on IOOverrides to override dart:io's classes behaviour.
Functions
-
withCurrentDirectory<
T> (String directory, FutureOr< T> action()) → FutureOr<T> -
Run the given
action
using the givendirectory
as the working directory. -
wrapWithCurrentDirectory<
T> (FutureOr< T> fun()) → FutureOr<T> Function() -
Wrap an existing function so that the returned function calls
withCurrentDirectory around it using
Directory.current.path
.