Search code examples
flutterfirebasegoogle-cloud-firestorefirebase-realtime-database

I am trying to read data from firebase realtime database but snapshot is marked in red


enter image description here

StreamBuilder(
              stream: _database
                  .child("orders")
                  .orderByKey()
                  .limitToLast(10)
                  .onValue,
              builder: (context,snapshot) {
                final tilesList = <ListTile>[];
                // Veri varsa işleme geç
                if (snapshot.hasData ) {
                  final myOrders = Map<String, dynamic>
                      .from((snapshot.data! as Event).snapshot.value);
                  tilesList.addAll(
                    myOrders.values.map((value) {
                      final nextOrder = Order.fromRTDB(Map<String,dynamic>.from(value));
                      return ListTile(
                        leading: Icon(Icons.coffee),
                        title: Text(nextOrder.description),
                        subtitle: Text(nextOrder.customerName),
                      );
                    }),
                );
                  return Expanded(
                      child: ListView(children: tilesList)
                  );
                } else {
                  return Center(child: Text('No data available'));
                }
              },
            )

I think I need to do type conversion, but how can I do this? enter image description here

enter image description here


Solution

  • The snapshot.data is a DatabaseEvent, not an Event.

    See the reference docs for the onValue stream.