add cartion filter and search
This commit is contained in:
103
lib/pages/carton/user_search_result.dart
Normal file
103
lib/pages/carton/user_search_result.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../helpers/theme.dart';
|
||||
import '../../domain/entities/user.dart';
|
||||
|
||||
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)),
|
||||
)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user