I am working on ChatApp trying to save and upload images but I get errors like this Does anyone know the cause of this ? im getting theese type of error i cant fnd any solutons for these..
import 'dart:io';
//Packages
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:file_picker/file_picker.dart';
const String USER_COLLECTION = "Users";
class CloudStorageService {
final FirebaseStorage _storage = FirebaseStorage.instance;
CloudStorageService();
Future<String?> saveUserImageToStorage(
String _uid, PlatformFile _file) async {
try {
Reference _ref =
_storage.ref().child('images/users/$_uid/profile.${_file.extension}');
UploadTask _task = _ref.putFile(
[enter image description here][1]File(_file.path),
);
return await _task.then(
(_result) => _result.ref.getDownloadURL(),
);
} catch (e) {
print(e);
}
}
Future<String?> saveChatImageToStorage(
String _chatID, String _userID, PlatformFile _file) async {
try {
Reference _ref = _storage.ref().child(
'images/chats/$_chatID/${_userID}_${Timestamp.now().millisecondsSinceEpoch}.${_file.extension}');
UploadTask _task = _ref.putFile(
File(_file.path), ----------------> Here is the error
);
return await _task.then(
(_result) => _result.ref.getDownloadURL(),
);
} catch (e) {
print(e);
}
}
}
PlatformFile.path
is astring?
. So, you need to check if thepath
is null or not before assigning to theFile