import 'package:fcs/domain/entities/fcs_shipment.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/material.dart'; import '../../../../helpers/theme.dart'; typedef OnAction = Future Function(); class ShipmentResult extends StatelessWidget { final bool isLoadingMore; final OnAction onLoadMore; final OnAction onRefresh; final Function(FcsShipment)? onTap; final ScrollController controller; final FcsShipment? selectedUser; final List searchResults; final String? noDataLabelKey; final bool isLoading; const ShipmentResult( {super.key, required this.isLoadingMore, required this.onLoadMore, required this.onRefresh, this.onTap, required this.controller, this.selectedUser, this.searchResults = const [], this.noDataLabelKey, this.isLoading = false}); bool _scrollNotification(ScrollNotification scrollInfo) { if (!isLoadingMore && scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) { onLoadMore(); } return true; } @override Widget build(BuildContext context) { return searchResults.isEmpty && !isLoading ? noDataLabelKey == null ? const SizedBox() : Center( child: LocalText(context, noDataLabelKey!, color: Colors.black, fontSize: 15)) : Column(children: [ Expanded( child: NotificationListener( onNotification: _scrollNotification, child: RefreshIndicator( color: primaryColor, onRefresh: () => onRefresh(), child: ListView.builder( controller: controller, shrinkWrap: true, physics: const AlwaysScrollableScrollPhysics(), itemBuilder: (context, index) { FcsShipment user = searchResults[index]; return ListTile( onTap: () { if (onTap != null) { onTap!(user); } }, title: Row( children: [ Text(user.shipmentNumber ?? "", style: const TextStyle( fontSize: 15, color: Colors.black)), const SizedBox( width: 20, ), selectedUser?.id == user.id ? const Icon( Icons.check, color: Colors.grey, ) : const SizedBox() ], ), ); }, itemCount: searchResults.length)), )), Container( height: isLoadingMore ? 50.0 : 0, color: Colors.transparent, child: const Center( child: CircularProgressIndicator( valueColor: AlwaysStoppedAnimation(primaryColor)), )), ]); } }