Files
fcs/lib/pages/carton/widget/user_search_result.dart

104 lines
3.8 KiB
Dart
Raw Permalink Normal View History

2024-02-07 17:26:29 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/material.dart';
2024-02-09 13:49:18 +06:30
import '../../../../helpers/theme.dart';
import '../../../domain/entities/user.dart';
2024-02-07 17:26:29 +06:30
typedef OnAction = Future<void> Function();
class UserSearchResult extends StatelessWidget {
final bool isLoadingMore;
final OnAction onLoadMore;
final OnAction onRefresh;
final Function(User)? onTap;
final ScrollController controller;
final User? selectedUser;
final List<User> searchResults;
final String? noDataLabelKey;
final bool isLoading;
const UserSearchResult(
{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<ScrollNotification>(
onNotification: _scrollNotification,
child: RefreshIndicator(
color: primaryColor,
onRefresh: () => onRefresh(),
child: ListView.builder(
controller: controller,
shrinkWrap: true,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (context, index) {
User user = searchResults[index];
return ListTile(
onTap: () {
if (onTap != null) {
onTap!(user);
}
},
title: Row(
children: [
Text(user.name ?? "",
style: const TextStyle(
fontSize: 15, color: Colors.black)),
user.fcsID == null
? const SizedBox()
: Padding(
padding: const EdgeInsets.only(left: 8),
child: Text(user.fcsID!,
style: const TextStyle(
fontSize: 15, color: labelColor)),
),
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<Color>(primaryColor)),
)),
]);
}
}