uploadImage function
Implementation
Future<String?> uploadImage(String _type, Uint8List _imageData) async {
if (_type != "customerAppLogo" && _type != "providerAppLogo" && _type != "webSiteAppLogo"
&& _type != "adminPanelAppLogo" && _type != "webSiteAvatar" && _type != "rating"
)
return "uploadImage: Unregistered type";
User? user = FirebaseAuth.instance.currentUser;
if (user == null)
return "uploadImage not register";
try{
var f = Uuid().v4();
localFile = "$f.jpg";
if (_type == "customerAppLogo" || _type == "providerAppLogo" || _type == "webSiteAppLogo"
|| _type == "adminPanelAppLogo")
localFile = "settings/$f.jpg";
if (_type == "webSiteAvatar")
localFile = "avatar/$f.jpg";
if (_type == "rating")
localFile = "rate/$f.jpg";
serverPath = await dbSaveFile(localFile, _imageData);
// var firebaseStorageRef = FirebaseStorage.instance.ref().child(localFile);
// TaskSnapshot s = await firebaseStorageRef.putData(_imageData);
// serverPath = await s.ref.getDownloadURL();
if (_type == "customerAppLogo"){
appSettings.customerLogoLocal = localFile;
appSettings.customerLogoServer = serverPath;
}
if (_type == "providerAppLogo"){
appSettings.providerLogoLocal = localFile;
appSettings.providerLogoServer = serverPath;
}
if (_type == "webSiteAppLogo"){
appSettings.websiteLogoLocal = localFile;
appSettings.websiteLogoServer = serverPath;
}
if (_type == "adminPanelAppLogo"){
appSettings.adminPanelLogoLocal = localFile;
appSettings.adminPanelLogoServer = serverPath;
}
if (_type == "webSiteAvatar"){
userAccountData.userAvatar = serverPath;
await FirebaseFirestore.instance.collection("listusers").doc(user.uid).set({
"localFile": localFile,
"logoServerPath": userAccountData.userAvatar
}, SetOptions(merge:true));
}
}catch(ex){
return "uploadFile " + ex.toString();
}
}