108 lines
3.0 KiB
Dart
108 lines
3.0 KiB
Dart
part of 'index.dart';
|
|
|
|
class DocumentManagerScreen extends StatelessScreen {
|
|
DocumentManagerScreen({
|
|
super.key,
|
|
required this.documents,
|
|
required this.categories,
|
|
});
|
|
|
|
List<Document> documents;
|
|
final List<Category> categories;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final GlobalKey<LocalSearchViewState> _listViewKey =
|
|
GlobalKey<LocalSearchViewState>();
|
|
|
|
bool filter(document, query) {
|
|
final lowerQuery = query.toLowerCase();
|
|
return document.title.toLowerCase().contains(lowerQuery) ||
|
|
document.description.toLowerCase().contains(lowerQuery) ||
|
|
document.category.title.toLowerCase().contains(lowerQuery) ||
|
|
document.to.toLowerCase().contains(lowerQuery) ||
|
|
document.from.toLowerCase().contains(lowerQuery) ||
|
|
document.createdAt.toLowerCase().contains(lowerQuery) ||
|
|
document.updatedAt.toLowerCase().contains(lowerQuery);
|
|
}
|
|
|
|
DocumentItem itemBuilder(dynamic item) {
|
|
log('item: $item');
|
|
|
|
final doc = Document(
|
|
createdAt: '00/00/00',
|
|
updatedAt: '00/00/00',
|
|
category: Category(color: Colors.black, title: item['category']),
|
|
to: item['person'],
|
|
from: '',
|
|
title: item['description'],
|
|
);
|
|
final docItem = DocumentItem(document: doc);
|
|
return docItem;
|
|
}
|
|
|
|
void filterByCategory(Category query) {
|
|
print('Test');
|
|
final state = _listViewKey.currentState;
|
|
|
|
if (state != null) {
|
|
state.safeSetState(() {
|
|
state.filteredItems = documents
|
|
.where((documents) => filter(documents, query.title))
|
|
.toList();
|
|
});
|
|
}
|
|
}
|
|
|
|
void unfilter(Category) {
|
|
final state = _listViewKey.currentState;
|
|
if (state != null) {
|
|
state.safeSetState(() {
|
|
state.filteredItems = documents;
|
|
});
|
|
}
|
|
}
|
|
|
|
final header = Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(15, 0, 50, 0),
|
|
child: Text('Últimos Documentos'),
|
|
),
|
|
CategoryCarousel(
|
|
categories: categories,
|
|
onSelect: filterByCategory,
|
|
onUnselect: unfilter,
|
|
),
|
|
],
|
|
);
|
|
List<Document> filterByString(String query) {
|
|
return documents.where((documents) => filter(documents, query)).toList();
|
|
}
|
|
|
|
final SizedBox space = SizedBox(height: 30);
|
|
|
|
return Column(
|
|
children: [
|
|
Expanded(
|
|
child: RemoteSearchListView<dynamic>(
|
|
key: _listViewKey,
|
|
header: header,
|
|
onSearch: filterByString,
|
|
list: documents,
|
|
itemBuilder: itemBuilder,
|
|
filter: filter,
|
|
title: '',
|
|
// fetchItems: (String ) { },,
|
|
),
|
|
),
|
|
] //
|
|
.addToStart(space)
|
|
.addToEnd(space),
|
|
);
|
|
}
|
|
}
|