5

I am using firebase realtime database with my Flutter Mobile Application. I am saving realtime data from an IoT device, a cloud function analyzes the data and generates analytics for my data on daily basis. As in following Database Structure, where "UsersData" is the root node, followed by user-uid and then his realtime readings and analytics.

enter image description here

Analytics are nested/saved as in following tree. Analytics contains data properly laid yearly as follow.

enter image description here

I want to fetch data for only single day, when I run the following query on Android it works totally fine and it return me data for single day. But on iOS it returns data for entire node.


  /// Getting Analytics for today Data
  Future getAnalyticsforSelectedDate({
    required String uid,
    required DateTime selectedDate,
  }) async {
    String selectedYear = selectedDate.year.toString();
    String selectedMonth = selectedDate.month.toString();
    String selectedDay = selectedDate.day.toString();

// Format Add a zero in front of single digit date such as
// e.g. Turn 9/9/2023 into 09/09/2023

    if (selectedDate.day >= 10) {
      selectedDay = selectedDate.day.toString();
    } else {
      selectedDay = "0" + selectedDate.day.toString();
    }

    if (selectedDate.month >= 10) {
      selectedMonth = selectedDate.month.toString();
    } else {
      selectedMonth = "0" + selectedDate.month.toString();
    }

    try {
      final data = await _db
          .child(
              "UsersData/$uid/analytics/$selectedYear/$selectedMonth/$selectedDay")
          .get();

      log("Date = $selectedDay/$selectedMonth/$selectedYear");
      log("${Platform.isIOS ? "IOS Results" : "Android Result"}:: ${data.value} ");

      return data.value;
    } catch (e) {
      log("@getAnalyticsforSelectedDate " + e.toString());
    }
  }

I am using latest firebase packages with Flutter Version 3.7.10.

firebase_auth: ^4.9.0
firebase_core: ^2.15.1
firebase_core_platform_interface: ^4.8.0
firebase_database: ^10.2.5
firebase_storage: ^11.2.6

I have tried running on iOS 16 and iOS 12 to see if it was a compatibility issue with old or new iOS version(same results on both).

Here what happens when I run the code for Date 18/09/2023 on Android Result logs on Android

Here is the log for iOS on Date 18/09/2023 iOS logs

6
  • The code you shared looks fine at first glance, but uses a lot of variables that we can't see the value of. Can you reproduce the problem when you pass a hard-coded path to child(...)? If so, can you show the updated code? It'd also be good to see the value you get back. So if you print(data.value), what do you get on iOS? And on other platforms? Commented Sep 19, 2023 at 13:11
  • @FrankvanPuffelen, thank you for your response. I have updated the question with outputs for each platform as well. You can notice that on iOS it returns entire node data while on Android it returns expected child node data only. Commented Sep 19, 2023 at 13:41
  • Thanks! --- Please check the other question I asked in my comment too. Commented Sep 19, 2023 at 13:44
  • I replaced all variables in the URL including day, month, year, uid (user-id). The issues is persistent on iOS and not happening on Android. Commented Sep 19, 2023 at 13:58
  • A team mate pointed out that you're using get() and we recall having a similar issue there at some point. Can you try to see if once does work consistenly across platforms? If so, that'd confirm it's a resurfacing bug in get() on iOS. Commented Sep 20, 2023 at 18:37

1 Answer 1

1

You're using the get() method, and I recall seeing some data loading issues with that on iOS at some point.

If you are affected by that issue, you should be able to use once() to work around it. If that indeed addresses it, I'll raise an issue with the engineering team for the bug you hit.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I really appreciate that. Yes, using .once() resolves my blockade at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.