Hello everyone
I have a tiny problem with my observable collection.
I am using firebase with a plugin (https://github.com/f-miyu/Plugin.CloudFirestore) and it works great, but I have two a problem
here I am saving a pet
pet.ImageURL = imageprincipal;
pet.id = Id.ToString();
pet.Nombre = NombreEntry.Text;
pet.FechaNacimiento = fechaNacimientoEntry.Text;
pet.Categoria = CategoriasPickerList.SelectedItem.ToString();
pet.Raza = RazaEntry.Text;
pet.Genero = GeneroPicker.SelectedItem.ToString();
pet.Tamaño = Tamañopicker.SelectedItem.ToString();
pet.Peso = pesoEntry.Text;
pet.Descripcion = DescripcionEntry.Text;
pet.Vacunado = Vacunado;
pet.Esterilizado = Esterilizado;
pet.RazaPura = RazaPura;
pet.Amistoso = Amistoso;
pet.Microship = Microchip;
pet.DisponibleParejas = Disponiple;
pet.ExtraImages = new System.Collections.Generic.List<string> {
mascota, mascota2, mascota3, mascota4
};
pet.Owner = auth.GetUserDisplayName();
await CrossCloudFirestore.Current
.Instance
.GetCollection("Pets")
.AddDocumentAsync(pet);
await Navigation.PopAsync(true);
}
and when I popAsync(), I go MyMascotas page, where I have a read method that gets invoke every time that page appears, but I dont see my new pet. I have to exit the screen and go back in in order for me to see it
private async void FabBtn_Clicked(object sender, System.EventArgs e) {
string accion = await DisplayActionSheet(null, "Cancelar",
null, "Usar camara", "Elegir de la galería", null);
switch (accion) {
case "Usar camara":
mediaFile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions {
Directory = "AppetLand Photos",
SaveToAlbum = true,
DefaultCamera = CameraDevice.Front
});
if (mediaFile == null) {
return;
}
img = ImageSource.FromStream(() => mediaFile.GetStream());
mascotaImg = await StoreImages(mediaFile.GetStream(), "Imagen principal", Path.GetExtension(mediaFile.Path));
Preferences.Set("Mascota Prinpipal", mascotaImg);
await Navigation.PushAsync(new PetInfoScreen(mascotaImg));
break;
case "Elegir de la galería":
mediaFile = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions { });
if (mediaFile == null) {
return;
}
img = ImageSource.FromStream(() => mediaFile.GetStream());
mascotaImg = await StoreImages(mediaFile.GetStream(), "Imagen principal", Path.GetExtension(mediaFile.Path));
Preferences.Set("Mascota Prinpipal", mascotaImg);
await Navigation.PushAsync(new PetInfoScreen(mascotaImg));
break;
default:
break;
}
}
protected override void OnAppearing() {
base.OnAppearing();
myMascotasViewModel.GetData();
}
I am using also a view model to back it up
public ObservableCollection<Pet> Pets { get; set; }
IAuth auth;
public MyMascotasViewModel() {
Pets = new ObservableCollection<Pet>();
auth = DependencyService.Get<IAuth>();
GetData();
}
public async void GetData() {
var document = await CrossCloudFirestore.Current
.Instance
.GetCollection("Pets")
.WhereEqualsTo("Owner", auth.GetUserDisplayName())
.GetDocumentsAsync();
var p = document.ToObjects<Pet>();
Pets.Clear();
foreach (var item in p) {
Pets.Add(item);
}
Debug.WriteLine(Pets.Count);
}