I'm working with data from Firebase RTDB. While I've successfully gotten the whole data from Firestore through this piece:
// GETTING ALL THE DATA FROM RTDB - MAP
void readSchool() async {
await realtime.once().then((DataSnapshot snapshot) {
setState(() {
schoolList = snapshot.value;
});
});
print('Data: $schoolList');
}
This is my RTDB data structure:
The Map I got from RTDB came out as nested Map (Map inside Map).
Data:
{
Kỹ thuật và Công nghệ:
{
color1: 0xfffaaca8, color2: 0xffb06ab3,
description: Nghiên cứu và sáng tạo các sản phẩm công nghệ cao,...,
oisp: {
imgcard: imgurl1,
category: KỸ THUẬT VÀ CÔNG NGHỆ,
title: Quốc tế Đại học Bách khoa TP.HCM,
location_s: Quận 10, Thành phố Hồ Chí Minh
}
},
Kinh tế và Quản lý:
{
color1: 0xffec6f66, color2: 0xfff3a183,
description: Tổ chức điều phối các hoạt động kinh tế, quản lý, tài chính,...,
ueh:
{
imgcard: imgurl2,
category: KINH TẾ VÀ QUẢN LÝ,
title: Đại học Kinh tế TP.HCM,
location_s: Quận 3, Thành phố Hồ Chí Minh}
}
}
Apparently, accessing a specific data using normal syntax such as
schoolList['Kỹ thuật và Công nghệ']['oisp']
doesn't trigger an analysis call of error but doesn't return a value neither.
Please help me access a specific data inside the data I retrieved from RTDB. Thank you!
I am trying to create some objects named HomeCard here:
// LIST OF ALL SCHOOL
Map schoolList;
// LIST OF FEATURED SCHOOL FROM FEATURED/RECOMMEND
List featuredSchool = [];
// LIST OF CATEGORIES FROM INFORMATION CATEGORIZE/LIST
List categories = [];
void homeCard() {
for (String category in categories) {
// ADD TO LIST
for (String school in featuredSchool) {
if (schoolList[category][school] as String != null) {
featuredCard.add(
// CARD TEMPLATE
HomeCard(
// FROM UNIVERSITY/INFORMATION/SCHOOL/[RECOMMENDED SCHOOL]/'TITLE'
name: schoolList[category][school]['title'] as String,
// FROM UNIVERSITY/INFORMATION/SCHOOL/[RECOMMENDED SCHOOL]/'CATEGORY'
category: schoolList[category][school]['category'] as String,
// FROM UNIVERSITY/INFORMATION/SCHOOL/[RECOMMENDED SCHOOL]/'IMGCARD'
networkImage:
NetworkImage(schoolList[category][school]['imgcard'] as String),
// CARD FUNCTION
function: () {},
),
);
String name = schoolList[category][school]['title'] as String;
print(name);
}
}
}
}
but it outputs an empty list