'Flutter - Get Snapshot Value from FirebaseAnimatedList

I am trying to get a list of my data from my Firebase Realtime Database. I am using the widget FirebaseAnimatedList to populate and correctly query the information.

While I try to reference the data snapshot, I am getting an error. For any Swift / UIKit programmers, I am trying to produce the following:

if let value = snapshot.value["name"] as? String {
  print(value)
}

I tried calling the snapshot.value['name'] here. Then I got an error that I needed to support optional functionality, and when I added the ?., I got another error that I can't:

enter image description here

final FirebaseDatabase database = FirebaseDatabase.instance;

DatabaseReference _categoriesRef = FirebaseDatabase.instance
      .ref()
      .child("Apps")
      .child(GlobalVariables.restaurantId)
      .child("menu")
      .child("categories");
Container(
  height: 50,
  child: new FirebaseAnimatedList(
    scrollDirection: Axis.horizontal,
    query: _categoriesRef,
    padding: EdgeInsets.fromLTRB(25, 0, 25, 0),
    itemBuilder: (
      BuildContext context,
      DataSnapshot snapshot,
      Animation<double> animation,
      int index,
    ) {
      var title = snapshot.value?.["hi there"];
      var titleText = "All ";
      return GestureDetector(
        onTap: () {
          setState(() {
            selectedIndex = index;
          });
        },
        child: Container(
          height: 20,
          child: categoryContainer(
            titleText,
              "hello",
              index,
            ),
          width: getWidth(titleText) + 50,
        ),
      );
    },
  ),
),

here is my data model



Sources

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

Source: Stack Overflow

Solution Source