Extracted UnifiedDeliveryListView from deliveries_page.dart to lib/components/unified_delivery_list.dart for better code organization and reusability. The component provides a unified delivery list experience supporting expanded and collapsed states for responsive sidebar layouts. Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
1.9 KiB
Dart
62 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../models/delivery.dart';
|
|
import '../l10n/app_localizations.dart';
|
|
import 'delivery_list_item.dart';
|
|
|
|
/// A unified list view for displaying deliveries with selection and action support.
|
|
///
|
|
/// This component provides a consistent delivery list experience across the app,
|
|
/// supporting both expanded and collapsed states for responsive sidebar layouts.
|
|
class UnifiedDeliveryListView extends StatelessWidget {
|
|
final List<Delivery> deliveries;
|
|
final Delivery? selectedDelivery;
|
|
final ScrollController scrollController;
|
|
final ValueChanged<Delivery> onDeliverySelected;
|
|
final Function(Delivery, String) onItemAction;
|
|
final bool isCollapsed;
|
|
|
|
const UnifiedDeliveryListView({
|
|
super.key,
|
|
required this.deliveries,
|
|
this.selectedDelivery,
|
|
required this.scrollController,
|
|
required this.onDeliverySelected,
|
|
required this.onItemAction,
|
|
this.isCollapsed = false,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context);
|
|
if (deliveries.isEmpty) {
|
|
return Center(
|
|
child: Text(l10n.noDeliveries),
|
|
);
|
|
}
|
|
|
|
return RefreshIndicator(
|
|
onRefresh: () async {
|
|
// Trigger refresh via provider
|
|
},
|
|
child: ListView.builder(
|
|
controller: scrollController,
|
|
padding: const EdgeInsets.only(top: 4, bottom: 8),
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
itemCount: deliveries.length,
|
|
itemBuilder: (context, index) {
|
|
final delivery = deliveries[index];
|
|
return DeliveryListItem(
|
|
delivery: delivery,
|
|
isSelected: selectedDelivery?.id == delivery.id,
|
|
onTap: () => onDeliverySelected(delivery),
|
|
onCall: () => onItemAction(delivery, 'call'),
|
|
onAction: (action) => onItemAction(delivery, action),
|
|
animationIndex: index,
|
|
isCollapsed: isCollapsed,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|