2020-11-12 17:28:57 +00:00
|
|
|
import 'dart:async';
|
2020-09-07 19:06:18 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
2021-06-22 21:04:49 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
2020-09-07 19:06:18 +00:00
|
|
|
class PlatformFile {
|
2021-06-22 21:04:49 +00:00
|
|
|
PlatformFile({
|
|
|
|
String? path,
|
2021-05-26 00:00:48 +00:00
|
|
|
required this.name,
|
|
|
|
required this.size,
|
2020-09-07 19:06:18 +00:00
|
|
|
this.bytes,
|
2020-11-12 17:28:57 +00:00
|
|
|
this.readStream,
|
2021-06-22 21:04:49 +00:00
|
|
|
}) : _path = path;
|
|
|
|
|
|
|
|
factory PlatformFile.fromMap(Map data, {Stream<List<int>>? readStream}) {
|
|
|
|
return PlatformFile(
|
|
|
|
name: data['name'],
|
|
|
|
path: data['path'],
|
|
|
|
bytes: data['bytes'],
|
|
|
|
size: data['size'],
|
|
|
|
readStream: readStream,
|
|
|
|
);
|
|
|
|
}
|
2020-09-09 23:52:45 +00:00
|
|
|
|
2020-12-13 16:04:55 +00:00
|
|
|
/// The absolute path for a cached copy of this file. It can be used to create a
|
2020-12-10 13:00:56 +00:00
|
|
|
/// file instance with a descriptor for the given path.
|
2020-09-11 17:01:34 +00:00
|
|
|
/// ```
|
|
|
|
/// final File myFile = File(platformFile.path);
|
|
|
|
/// ```
|
2021-05-26 00:00:48 +00:00
|
|
|
/// On web this is always `null`. You should access `bytes` property instead.
|
|
|
|
/// Read more about it [here](https://github.com/miguelpruivo/flutter_file_picker/wiki/FAQ)
|
2021-06-22 21:04:49 +00:00
|
|
|
String? _path;
|
|
|
|
|
|
|
|
String get path {
|
|
|
|
if (kIsWeb) {
|
|
|
|
/// https://github.com/miguelpruivo/flutter_file_picker/issues/751
|
|
|
|
throw '''
|
|
|
|
On web `path` is always `null`,
|
|
|
|
You should access `bytes` property instead,
|
|
|
|
Read more about it [here](https://github.com/miguelpruivo/flutter_file_picker/wiki/FAQ)
|
|
|
|
''';
|
|
|
|
}
|
|
|
|
return _path!;
|
|
|
|
}
|
2020-09-07 19:06:18 +00:00
|
|
|
|
|
|
|
/// File name including its extension.
|
2021-05-26 00:00:48 +00:00
|
|
|
final String name;
|
2020-09-07 19:06:18 +00:00
|
|
|
|
2020-09-09 23:52:45 +00:00
|
|
|
/// Byte data for this file. Particurlarly useful if you want to manipulate its data
|
|
|
|
/// or easily upload to somewhere else.
|
2021-05-26 00:00:48 +00:00
|
|
|
/// [Check here in the FAQ](https://github.com/miguelpruivo/flutter_file_picker/wiki/FAQ) an example on how to use it to upload on web.
|
2020-11-21 21:26:32 +00:00
|
|
|
final Uint8List? bytes;
|
2020-09-07 19:06:18 +00:00
|
|
|
|
2020-11-12 17:28:57 +00:00
|
|
|
/// File content as stream
|
2020-11-21 21:26:32 +00:00
|
|
|
final Stream<List<int>>? readStream;
|
2020-11-12 17:28:57 +00:00
|
|
|
|
2021-01-04 15:10:27 +00:00
|
|
|
/// The file size in bytes.
|
2021-05-26 00:00:48 +00:00
|
|
|
final int size;
|
2020-09-09 23:52:45 +00:00
|
|
|
|
2020-09-07 19:06:18 +00:00
|
|
|
/// File extension for this file.
|
2021-05-26 00:00:48 +00:00
|
|
|
String? get extension => name.split('.').last;
|
2021-08-29 00:57:02 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) {
|
2021-08-31 11:02:15 +00:00
|
|
|
if (identical(this, other)) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-08-29 00:57:02 +00:00
|
|
|
|
|
|
|
return other is PlatformFile &&
|
|
|
|
other.path == path &&
|
|
|
|
other.name == name &&
|
|
|
|
other.bytes == bytes &&
|
|
|
|
other.readStream == readStream &&
|
|
|
|
other.size == size;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode {
|
|
|
|
return path.hashCode ^
|
|
|
|
name.hashCode ^
|
|
|
|
bytes.hashCode ^
|
|
|
|
readStream.hashCode ^
|
|
|
|
size.hashCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return 'PlatformFile(path: $path, name: $name, bytes: $bytes, readStream: $readStream, size: $size)';
|
|
|
|
}
|
2020-09-07 19:06:18 +00:00
|
|
|
}
|