fix PlatformFile path is always null on web

This commit is contained in:
Ahmed Masoud 2021-06-22 23:04:49 +02:00 committed by GitHub
parent 9f0a811028
commit 9e6c9d6266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 9 deletions

View File

@ -1,20 +1,26 @@
import 'dart:async'; import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/foundation.dart';
class PlatformFile { class PlatformFile {
const PlatformFile({ PlatformFile({
String? path,
required this.name, required this.name,
required this.size, required this.size,
this.path,
this.bytes, this.bytes,
this.readStream, this.readStream,
}); }) : _path = path;
PlatformFile.fromMap(Map data, {this.readStream}) factory PlatformFile.fromMap(Map data, {Stream<List<int>>? readStream}) {
: this.path = data['path'], return PlatformFile(
this.name = data['name'], name: data['name'],
this.bytes = data['bytes'], path: data['path'],
this.size = data['size']; bytes: data['bytes'],
size: data['size'],
readStream: readStream,
);
}
/// The absolute path for a cached copy of this file. It can be used to create a /// The absolute path for a cached copy of this file. It can be used to create a
/// file instance with a descriptor for the given path. /// file instance with a descriptor for the given path.
@ -23,7 +29,19 @@ class PlatformFile {
/// ``` /// ```
/// On web this is always `null`. You should access `bytes` property instead. /// 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) /// Read more about it [here](https://github.com/miguelpruivo/flutter_file_picker/wiki/FAQ)
final String? path; 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!;
}
/// File name including its extension. /// File name including its extension.
final String name; final String name;