Closeable class abstract
An object that may hold resources until it is closed.
The close method is invoked to release resources that the object is holding (such as open files). The close method is idempotent - calling it multiple times should have no additional effect.
Example Usage
class FileResource implements Closeable {
final File _file;
bool _closed = false;
FileResource(String path) : _file = File(path);
@override
Future<void> close() async {
if (_closed) return;
_closed = true;
// Perform cleanup
}
}
// Usage with try-finally
final resource = FileResource('data.txt');
try {
// Use resource
} finally {
await resource.close();
}
- Implementers
Constructors
- Closeable()
- An object that may hold resources until it is closed.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> - Closes this resource, relinquishing any underlying resources.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited