How to implement Firebase Realtime Database in .NET MAUI with complex data
I am using NET MAUI and Firebase Realtime Database , I ma uploading some user data in Firebase Realtime Database , and i fetch my all data from my view model but it's take to much time to load and when i add some more new data then it's takes to much time to reflect in my app . How can remove this delay time to make my app faster.
public ProfilePageViewModel(INavigation navigation, FirebaseManager _firebaseManager)
{
firebaseClient = new FirebaseClient(DatabaseUrl);
Navigation = navigation;
firebaseManager = _firebaseManager;
PaymentMethods = new ObservableCollection<PaymentModel>();
LoadUserData();
}
private async void LoadUserData()
{
await FetchUserDataAsync();
}
public async Task FetchUserDataAsync()
{
UserId = Preferences.Get("LocalId", string.Empty);
IsLoading = true;
var observable = firebaseClient
.Child("UserData")
.Child(UserId)
.AsObservable<UserDataModel>();
observable.Subscribe(user =>
{
UserData = user.Object;
FullName = UserData.FirstName + " " + UserData.LastName;
}, error =>
{
Console.WriteLine("Error while fetching user data: " + error.Message); }); IsLoading = false;
}
}
public class UserDataModel
{
public string Id { get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string MobileNumber { get; set; }
public ObservableCollection<PaymentModel> PaymentMethod { get; set; } = new ObservableCollection<PaymentModel>();
public string Image { get; set; }
public string Address { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
public partial class PaymentModel : ObservableObject
{
public string PaymentEmail { get; set; }
public string CardNumber { get; set; }
public string CVV { get; set; }
public string ExpiryDate { get; set; }
public string PaymentMethodName { get; set; }
}