PlatformService class abstract

Platform abstraction layer that hides dart:io from the web frontend.

On native platforms (macOS, Linux, Windows) the implementation delegates directly to dart:io. On the web the implementation proxies every call to a local REST server running on localhost:3219.

Usage:

import 'package:neomage/core/platform/platform_init.dart';

void main() {
  initializePlatform();
  final ps = PlatformService.instance;
  final content = await ps.readFile('/tmp/hello.txt');
}
Implementers

Constructors

PlatformService()

Properties

currentDirectory String
Current working directory.
no setter
environmentVariables Map<String, String>
All environment variables.
no setter
hashCode int
The hash code for this object.
no setterinherited
homeDirectory String
User home directory (e.g. /Users/me).
no setter
localHostname String
Local hostname.
no setter
numberOfProcessors int
Number of processors available.
no setter
operatingSystem String
Operating system identifier (e.g. macos, linux, windows, web).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tempDirectory String
System temp directory.
no setter

Methods

appendFile(String path, String content) Future<void>
Append content to the end of the file at path.
connectWebSocket(Uri url) Future<PlatformWebSocket>
Open a WebSocket connection to url.
copyFile(String source, String destination) Future<void>
Copy a file from source to destination.
createDirectory(String path, {bool recursive = true}) Future<void>
Create a directory at path.
createTempDirectory({String? prefix}) Future<String>
Create a temporary directory and return its path.
createTempFile({String? prefix, String? suffix}) Future<String>
Create a temporary file and return its path.
deleteDirectory(String path, {bool recursive = false}) Future<void>
Delete the directory at path. If recursive is true, delete contents.
deleteFile(String path) Future<void>
Delete the file at path.
directoryExists(String path) Future<bool>
Whether a directory exists at path.
fileExists(String path) Future<bool>
Whether a file exists at path.
httpRequest(String method, Uri url, {Map<String, String>? headers, Object? body, Duration? timeout}) Future<PlatformHttpResponse>
Perform an HTTP request.
listDirectory(String path, {bool recursive = false}) Future<List<String>>
List entries inside path. When recursive is true, descend into sub-directories.
moveFile(String source, String destination) Future<void>
Move / rename a file from source to destination.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readFile(String path) Future<String>
Read file at path as a UTF-8 string.
readFileBytes(String path) Future<Uint8List>
Read file at path as raw bytes.
runProcess(String executable, List<String> arguments, {String? workingDirectory, Map<String, String>? environment, Duration? timeout, bool runInShell = false}) Future<ProcessOutput>
Run a process to completion and capture its output.
startProcess(String executable, List<String> arguments, {String? workingDirectory, Map<String, String>? environment, bool runInShell = false}) Future<RunningProcess>
Start a long-running process and return a handle that exposes output streams and a kill method.
statFile(String path) Future<PlatformFileStat>
Return metadata for the entity at path.
toString() String
A string representation of this object.
inherited
watchDirectory(String path, {bool recursive = true}) Stream<FileChangeEvent>
Watch path for filesystem changes.
writeFile(String path, String content) Future<void>
Write content (UTF-8) to file at path, creating parent dirs as needed.
writeFileBytes(String path, Uint8List bytes) Future<void>
Write raw bytes to file at path, creating parent dirs as needed.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance PlatformService
no setter

Static Methods

initialize(PlatformService impl) → void
Must be called once at application startup.