addDataItem method
Adds a data item to Firebase.
If _data is null, returns an error result.
If _file is not null, uploads the file and adds the data to Firestore.
Otherwise, adds the data directly to Firestore.
@param id The optional document ID to use for the new data item.
Returns a Result containing the added data or an error.
Implementation
@override
Future<Result<RemoteBaseModel, RemoteBaseModel>> addDataItem({String? id }) async {
try {
if (_data == null) {
return Result.error(RemoteBaseModel(message: "data is null"));
}
if (_file != null) {
var result = await _fireStoreAction
.addDataCloudFirestorWithUploadCollectionPathes(
id: id ,
pathes: _path,
mymap: _data!.toJson(),
file: _file,
imageField: imageField!);
return Result.data(RemoteBaseModel(data: result));
} else {
var result = await _fireStoreAction.addDataCloudFirestore(
id: id ,
path: _path, mymap: _data!.toJson());
return Result.data(RemoteBaseModel(data: result));
}
} on Exception catch (e) {
return Result.error(RemoteBaseModel(message: e.toString()));
}
}