'Dart/Flutter & Firebase RTDB - How to access the nested Map retrieved from RTDB

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:

RTDB

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



Solution 1:[1]

You're whitelisting an array when you just need a single param:

protected
 
def configure_permitted_parameters
  devise_parameter_sanitizer.permit(:sign_up) do |user_params|
    user_params.permit(:role, :full_name,:email, :password, :password_confirmation)
  end
end

You should also fix the view so that you're using the same argument for the label and input:

<div class="field">
  <%= f.label :role %>
  <%= f.select :role, collection: User.roles.keys.to_a %>
</div>

This is important for assistive technologies such as screenreaders so that they can properly link the label to the input via the for attribute.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 max