I got data that structure like this inside firebase RTDB.

enter image description here

My goal is to retrieve Product (Name) value if my barcode scanner detected matched value inside Product (Code). I already have a similar function written like this to check whether Barcode Scanner found ID value on another page. Which will then return into a list of everything inside through listitem.

late Query _ref =
              defaultChild: Center(child: const CircularProgressIndicator()),
              shrinkWrap: true,
              query: _ref,
              itemBuilder: (BuildContext context, DataSnapshot snapshot,
                  Animation<double> animation, int index) {
                Map database = snapshot.value as Map;
                database['key'] = snapshot.key;
                return listitem(database: database);

    Widget listitem({required Map database}) {
        if (database['Serial']?.isEmpty ?? true) {
          const String novalue = 'NULL';
          return ProductList(
            productcode: database['Product (Code)'],
            productname: database['Product (Name)'],
            quantity: database['Number'],
            phyid_result: widget.phyid,
            serial: novalue,

From my understanding, DataSnapshot snapshot return data as 'List(Object?)' which then i can convert into Map in order to query the data using [] bracket as key.

So i though by doing something similar. I could do the same thing again. But this time i simply want it to return based on scanned Product (Code)

  final ref = FirebaseDatabase.instance.ref();
              fit: BoxFit.cover,
              allowDuplicates: false,
              controller: MobileScannerController(
                  facing: CameraFacing.back, torchEnabled: false),
              onDetect: (barcode, args) {
                try {
                  BarcodeScanner_Product.code = barcode.rawValue!;
                      .orderByChild('Product (Code)')
                      .then((DataSnapshot snapshot) {
                    if (snapshot.exists) {
                      Map data = snapshot.value as Map;
                          isScrollControlled: true,
                          context: context,
                          builder: (context) {
                            return oneitem(data: data);
                    } else {
                      print('Not Exist');
    Widget oneitem({required Map data}) {
        return Wrap(children: <Widget>[
            database_phyid: BarcodeScanner.code,
            scanned_product_code: BarcodeScanner_Product.code,
            scanned_product_name: data['Product (Name)'],
            need_quantity: 25,//TEMP
            total_quantity_needed: 26,//TEMP

Instead, i got an error.

Unhandled Exception: type 'List<Object?>' is not a subtype of type 'Map<dynamic, dynamic>' in type cast

I'm not sure where my issue is. It seems like exact same thing. Or am i misunderstood the way it works? Maybe the reason my first block of code works is because of Query and FirebaseAnimatedList?

Either way i've been scouring all over the internet for entire day and haven't found an answer for this. So if anyone can explain what am i doing wrong, I'd be appreciated.