Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting the Stack Overflow error?

I get a Stack Overflow error but I don't seem to know what's wrong. This is Database class helps me to get FirebaseDatabase information.

 import 'package:firebase_database/firebase_database.dart';
    import 'User.dart';
    import 'dart:async';


    class FireDatabase{
      FireDatabase();

      DatabaseReference userRef = FirebaseDatabase.instance.reference().child("users");
      DatabaseReference transactionsRef = FirebaseDatabase.instance.reference().child("transactions");
      User user = new User();


     getDatabaseUser(String cUid){
        userRef.orderByChild(cUid).once().then((DataSnapshot data){
          if (data.value!=null) {
            return data.value;
          } else {
            print("prints - database.dart : data.value of user is empty/null");
            return null;
          }
        },onError: (e){
          print("prints - database.dart " + e.toString());
          return null;
        });
        return null;
      }

      getDatabaseTransactions(String cUid) {
        transactionsRef.orderByChild("transactions").once().then((DataSnapshot data){
          if(data.value!=null) {
            return data.value;
          } else {
            print("prints - database.dart : data.value of user is empty/null");
            return null;
          }
        },onError: (e){
          print("prints - database.dart " + e.toString());
          return null;
        });
        return null;
      }

      getDatabaseTransaction(String cUid) {
        transactionsRef.orderByChild(cUid).limitToFirst(1).once().then((DataSnapshot data){
          if(data.value!=null) {
            return data.value;
          } else {
            print("prints - database.dart : data.value of user is empty/null");
            return null;
          }
        },onError: (e){
          print("prints - database.dart " + e.toString());
          return null;
        });
        return null;
      }

    }
like image 872
Thapelo Radebe Avatar asked Nov 18 '22 06:11

Thapelo Radebe


1 Answers

For me, the problem was that I had 2 classes, now within both classes, I instantiated each other class.

Here is an example:

class Firestore{
  final auth = Auth();
}


class Auth{
  final fireStore = Firestore();
}

As you can see each class is calling the other class, that what caused the StackOverflow.

like image 53
MendelG Avatar answered Dec 23 '22 19:12

MendelG