I have problem in model class for fetching data from real-time firebase database into list but receiving null. Further clarify by images below:
This is image that data to fetch.
This is a model class:
class Seller {
var key;
String address,
businessType,
description,
fcm,
joinTimeStamp,
name,
onlineStatus,
picUrl,
uuid;
int blockByAdmin, completeOrders, rating;
double lat;
double lng;
Seller(
this.address,
this.blockByAdmin,
this.businessType,
this.description,
this.completeOrders,
this.fcm,
this.joinTimeStamp,
this.lat,
this.lng,
this.name,
this.onlineStatus,
this.picUrl,
this.rating,
this.uuid);
Seller.fromSnapshot(DataSnapshot snapshot)
: key = snapshot.value,
address = snapshot.value["address"],
blockByAdmin = snapshot.value["blockByAdmin"],
businessType = snapshot.value["businessType"],
description = snapshot.value["description"],
completeOrders = snapshot.value["completeOrders"],
fcm = snapshot.value["fcm"],
joinTimeStamp = snapshot.value["joinTimeStamp"],
lat = snapshot.value["lat"],
lng = snapshot.value["lng"],
name = snapshot.value["name"],
onlineStatus = snapshot.value["onlineStatus"],
picUrl = snapshot.value["picUrl"],
rating = snapshot.value["rating"],
uuid = snapshot.value["uuid"];
toJson() {
return {
'address': address,
'blockByAdmin': blockByAdmin,
'businessType': businessType,
'description': description,
'completeOrders': completeOrders,
'fcm': fcm,
'joinTimeStamp': joinTimeStamp,
'lat': lat,
'lng': lng,
'name': name,
'onlineStatus': onlineStatus,
'picUrl': picUrl,
'rating': rating,
'uuid': uuid,
};
}
}
This is a class where we are using model class and getting null at list length:
class Body extends StatefulWidget {
@override
_BodyState createState() => _BodyState();
}
class _BodyState extends State<Body> {
final urlImage =
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSPlqk-tNmFTjT7q_edAjaYLU5qf2cFUM9vfrweUbqnS_58LqF7AMp67KVdslIubuzy9b4&usqp=CAU';
final _database = FirebaseDatabase.instance.reference().child('kjobhee');
List<Seller> _sellerList;
StreamSubscription<Event> _onTodoAddedSubscription;
Query _query;
@override
void initState() {
super.initState();
_activateListeners();
}
void _activateListeners() {
_query = _database.child('seller');
_onTodoAddedSubscription = _query.onValue.listen(onEntryAdded);
}
onEntryAdded(Event event) {
setState(() {
_sellerList.add(Seller.fromSnapshot(event.snapshot));
print(_sellerList);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: kPrimaryColor,
),
drawer: NavigationDrawer(),
body: RefreshIndicator(
onRefresh: () => _buildBuyerProfile(),
child: _sellerList.length > 0
? ListView.builder(
shrinkWrap: true,
itemCount: _sellerList.length,
itemBuilder: (BuildContext context, int index) {
String key = _sellerList[index].key;
String address = _sellerList[index].address;
int blockByAdmin = _sellerList[index].blockByAdmin;
String businessType = _sellerList[index].businessType;
String description = _sellerList[index].description;
int completeOrders = _sellerList[index].completeOrders;
String fcm = _sellerList[index].fcm;
String joinTimeStamp = _sellerList[index].joinTimeStamp;
double lat = _sellerList[index].lat;
double lng = _sellerList[index].lng;
String name = _sellerList[index].name;
String onlineStatus = _sellerList[index].onlineStatus;
String picUrl = _sellerList[index].picUrl;
int rating = _sellerList[index].rating;
String uuid = _sellerList[index].uuid;
print(key +
'/' +
address +
'/' +
blockByAdmin.toString() +
'/' +
businessType +
'/' +
description +
'/' +
completeOrders.toString() +
'/' +
fcm +
'/' +
joinTimeStamp +
'/' +
lat.toString() +
'/' +
lng.toString() +
'/' +
name +
'/' +
onlineStatus +
'/' +
picUrl +
'/' +
rating.toString() +
'/' +
uuid);
return _buildBuyerProfile();
})
: Center(
child: CircularProgressIndicator(),
),
),
);
}
I would be very grateful for any user help.