Home > database >  The getter '(' isn't defined for the type
The getter '(' isn't defined for the type

Time:10-01

I have this code block that I want to use to retrieve data from firebase database. But I have issue with the code as it brings error message as below. Please I need help to resolve the issue. The error message

The getter '(' isn't defined for the type 'UsersData'. Try importing the library that defines '(', correcting the name to the name of an existing getter, or defining a get

The code

void _getPhoneNos(BuildContext context) async {
fb.Database db = fb.database();
fb.DatabaseReference<ReferenceJsImpl> dataRef = db.ref('users');
dataRef.onValue.listen((event) {
  fb.DataSnapshot snapshot = event.snapshot;

  if (snapshot == null) {
    print("Result is Empty");
    return;
  }
   List<UsersData>usersInfo= snapshot.val();

     usersInfo.forEach((Item) {
    _singleTextFieldcontroller.text = Item.Item("phone");
  });
});

This is the UsersData.

  class UsersData {
  String id;
  String name;
  String type;
  String phone;
  String residential;

  UsersData({
    this.id,
    this.name,
    this.type,
    this.phone,
    this.residential,
  });

  UsersData.fromJson(this.id, Map data) {
    name = data['name'];
    type = data['type'];
    phone = data['phone'];
    residential = data['residential'];
  }

  
}

CodePudding user response:

An 's' is missing :

UserData({
    this.id,
    this.name,
    this.type,
    this.phone,
    this.residential,
  });

Should be

UsersData({
    this.id,
    this.name,
    this.type,
    this.phone,
    this.residential,
  });

CodePudding user response:

There is an error in this line :

_singleTextFieldcontroller.text = Item.Item("phone");

Item is an instance of UsersData. If you want to access their phone variable you should do :

_singleTextFieldcontroller.text = Item.phone;
  • Related