StatefulElement (StreamBuilder<DatabaseEvent>(dirty, state: _StreamBuilderBaseState<DatabaseEvent, AsyncSnapshot<DatabaseEvent>>#80184))
12:27 23 Mar 2026

I am new to flutter and am having a problem where I can't retrieve data from database and show it in a list view. it works on the android sometimes but always crushes on iOS with the error "StatefulElement (StreamBuilder(dirty, state: _StreamBuilderBaseState>#80184))" in the title above. please assist me .

here is my code.

import 'package:cargoit_users_app_mk2/widgets/loading_dialog.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';

class CompletedTripsHistory extends StatefulWidget {
  const CompletedTripsHistory({super.key});

  @override
  State createState() => _CompletedTripsHistoryState();
}

class _CompletedTripsHistoryState extends State {

  final rideReuests = FirebaseDatabase.instance.ref().child("rideRequests");


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.grey[500],
        title: const Text("Completed deliveries",
        style: TextStyle(
          color: Colors.black,
        ),
      ),
      centerTitle: true,
      leading: IconButton(
        onPressed: (){
          Navigator.pop(context);
        }, 
        icon: const Icon(Icons.arrow_back, color: Colors.amber,),
        ),
      ),
      body: StreamBuilder(
        stream: rideReuests.onValue,
         builder: (BuildContext context, dataSnapShot) {
          

          Map tripsMap = dataSnapShot.data!.snapshot.value as Map;
          List allTripsList = [];
          tripsMap.forEach((key, value) => allTripsList.add({"key": key, ...value}));

          return ListView.builder(
            shrinkWrap: true,
            itemCount: allTripsList.length,
            itemBuilder: ((context, index) 
            {
              if(allTripsList[index]["status"] != null 
              && allTripsList[index]["status"] == "ended" 
              && allTripsList[index]["userID"] == FirebaseAuth.instance.currentUser!.uid)
              
              {
                
                return Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Card(
                    color: Colors.grey[500],
                    elevation: 12,
                    child: Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [

                          Row(
                            children: [

                              Image.asset("assets/redpin.PNG", height: 16, width: 16,),

                              const SizedBox(width: 18,),

                              Expanded(
                                child: Text(
                                  allTripsList[index]["pickUpAddress"].toString(),
                                  overflow: TextOverflow.ellipsis,
                                  style: const TextStyle(
                                    fontSize: 18,
                                    color: Colors.black,
                                  ),
                                )),

                                const SizedBox(width: 5,),

                                Text(
                                  "\R ${allTripsList[index]["fareAmount"]}",
                                  style: const TextStyle(
                                    fontSize: 24,
                                    color: Colors.black,
                                    fontWeight: FontWeight.bold,
                                  ),
                                )
                            ],
                          ),

                          const SizedBox(height: 10,),

                          Row(
                            children: [

                              Image.asset("assets/greenpin.PNG", height: 16, width: 16,),

                              const SizedBox(width: 18,),

                              Expanded(
                                child: Text(
                                  allTripsList[index]["dropOffAddress"].toString(),
                                  overflow: TextOverflow.ellipsis,
                                  style: const TextStyle(
                                    fontSize: 18,
                                    color: Colors.black,
                                  ),
                                ))


                            ],
                          )




                        ],
                      ),
                  ),
                ),
                );


              }
              else {
                return Container(
                  child: Text("No completed deliveries."),
                );
              }

            })
          );
         }),
    );
  }
}
flutter dart stream-builder