build method
- BuildContext context
override
Builds the UI for the order history screen.
Displays a list of orders using a StreamBuilder to listen for updates from
_getConsumerOrders. Shows a loading indicator, an empty state message, or
a list of ConsumerOrderCard widgets based on the stream's state.
Parameters:
- context: The BuildContext for building the widget.
Returns: A Widget representing the order history screen UI.
Implementation
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Order History')),
body: StreamBuilder<QuerySnapshot>(
stream: _getConsumerOrders(context),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (!snapshot.hasData || snapshot.data!.docs.isEmpty) {
return const Center(
child: Text(
'No orders yet',
style: TextStyle(fontSize: 18),
),
);
}
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
final orderData =
snapshot.data!.docs[index].data() as Map<String, dynamic>;
return ConsumerOrderCard(orderData: orderData);
},
);
},
),
);
}