Artisans Express
Artisans Express

Reputation: 11

The getter '(' isn't defined for the type

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

  
}

Upvotes: 1

Views: 3124

Answers (2)

Tanguy
Tanguy

Reputation: 984

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;

Upvotes: 0

Tanguy
Tanguy

Reputation: 984

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

Upvotes: 0

Related Questions