ScopedStorageXFile class base

A reference to a data resource within a device's scoped storage.

Scoped storage limits app access to external storage and apps may lose access to a resource at any point depending on the platform.

Platform-Specific Features

This class contains an underlying implementation provided by the current platform. Once a platform implementation is imported, the examples below can be followed to use features provided by a platform's implementation.

Below is an example of setting platform-specific creation parameters for the Android implementation of cross_file:

late final PlatformScopedStorageCreationParams params;

switch(CrossFile.implementation) {
  case CrossFileWeb():
    params = WebScopedStorageXFileCreationParams.fromObjectUrl(
      objectUrl: 'blob:https://some/url:for/file',
    );
  case CrossFileAndroid():
    params = PlatformScopedStorageXFileCreationParams(
      uri: 'content://my/file.txt'
    );
  default:
    params = PlatformScopedStorageXFileCreationParams(
      uri: 'my/file.txt'
    );
}

final file = ScopedStorageXFile.fromCreationParams(params);

Below is an example of accessing the platform-specific extension for the Android implementation of cross_file:

final ScopedStorageXFile file = ScopedStorageXFile(uri: 'content://my/file.txt');

final AndroidScopedStorageXFileExtension? androidExtension =
    file.getExtension<AndroidScopedStorageXFileExtension>();
if (androidExtension != null) {
  print(androidExtension.name());
}
Inheritance
Annotations

Constructors

ScopedStorageXFile({required String uri})
Constructs a ScopedStorageXFile.
ScopedStorageXFile.fromCreationParams(PlatformScopedStorageXFileCreationParams params)
Constructs a ScopedStorageXFile from creation params for a specific platform.
ScopedStorageXFile.fromUri(Uri uri)
Constructs a ScopedStorageXFile.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
uri → String
A unique string used to identify the resource.
no setterinherited

Methods

canRead() → Future<bool>
Whether the resource represented by this reference can be read.
dispose() → Future<void>
Release the reference this represents.
exists() → Future<bool>
Whether the resource represented by this reference exists.
inherited
getExtension<S extends PlatformXEntityExtension>() → S?
Attempt to provide the platform class extension.
inherited
lastModified() → Future<DateTime?>
Date and time when the resource was last modified, if the information is available.
inherited
length() → Future<int?>
The length of the data represented by this uri, in bytes.
inherited
name() → Future<String?>
The name of the resource represented by this object or null if the file doesn't exist or information is not available.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openRead([int? start, int? end]) → Stream<Uint8List>
Creates a new independent Stream for the contents of this resource.
inherited
readAsBytes() → Future<Uint8List>
Reads the entire resource contents as a list of bytes.
inherited
readAsString({Encoding encoding = utf8}) → Future<String>
Reads the entire resource contents as a string using the given Encoding.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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