How to implement Firebase Realtime Database in .NET MAUI with complex data

Md Mosabbir Alam 20 Reputation points
2024-10-21T09:39:45.34+00:00

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; }  

}

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,363 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,637 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,046 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.