93 lines
2.6 KiB
Dart
93 lines
2.6 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(document) => DocumentItem(document: document);
|
|
|
|
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: LocalSearchView<Document>(
|
|
key: _listViewKey,
|
|
header: header,
|
|
onSearch: filterByString,
|
|
list: documents,
|
|
itemBuilder: itemBuilder,
|
|
filter: filter,
|
|
),
|
|
),
|
|
] //
|
|
.addToStart(space)
|
|
.addToEnd(space),
|
|
);
|
|
}
|
|
}
|