169 lines
4.9 KiB
Dart
169 lines
4.9 KiB
Dart
part of 'index.dart';
|
|
|
|
class DocumentPageModel extends FlutterFlowModel<DocumentPage> {
|
|
DocumentPageModel();
|
|
|
|
late final GlobalKey<State<FutureBuilder>> pageKey;
|
|
late final EnhancedRemoteListViewKey<Document, Category, Null>
|
|
enhancedListViewKey;
|
|
late final DocumentKey viewerKey;
|
|
late final PagingController<int, Document> _pagingController;
|
|
|
|
/// ------------
|
|
|
|
@override
|
|
void initState(BuildContext context) {
|
|
pageKey = GlobalKey<State<FutureBuilder>>();
|
|
enhancedListViewKey = EnhancedRemoteListViewKey<Document, Category, Null>();
|
|
viewerKey = DocumentKey();
|
|
|
|
_pagingController = PagingController<int, Document>(firstPageKey: 1);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_pagingController.dispose();
|
|
// isCategorySelected = false;
|
|
// isDocumentSelected = false;
|
|
}
|
|
|
|
/// ------------
|
|
|
|
/// [onView]
|
|
void onView(Document document, BuildContext context) async {
|
|
context.read<DocumentPageBloc>().add(SelectDocumentEvent(document));
|
|
}
|
|
|
|
/// [itemBodyBuilder]
|
|
DocumentItem itemBodyBuilder<T extends Document>(
|
|
BuildContext context, T item, int index) {
|
|
print('ItemBuilder -> $index');
|
|
return DocumentItem(
|
|
document: item,
|
|
onPressed: onView,
|
|
);
|
|
}
|
|
|
|
CategoryItem categoryItemBuilder<T>(T? item) {
|
|
return CategoryItem(category: item! as Category);
|
|
}
|
|
|
|
/// [itemHeaderBuilder]
|
|
Widget itemHeaderBuilder<T>(Future<List<T?>> Function() gen) =>
|
|
Builder(builder: (context) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(15, 0, 50, 0),
|
|
child: Text(
|
|
FFLocalizations.of(context).getVariableText(
|
|
enText: 'Recent Documents', ptText: 'Últimos Documentos'),
|
|
style: TextStyle(
|
|
color: FlutterFlowTheme.of(context).primaryText,
|
|
fontSize: LimitedFontSizeUtil.getHeaderFontSize(context),
|
|
),
|
|
),
|
|
),
|
|
EnhancedCarouselView<T>(
|
|
generateItems: gen,
|
|
itemBuilder: categoryItemBuilder,
|
|
filter: filter<T>,
|
|
),
|
|
],
|
|
);
|
|
});
|
|
|
|
/// [generateBodyItems]
|
|
Future<List<T?>> generateBodyItems<T extends Document>(
|
|
int pageKey, int pageSize, dynamic query) async {
|
|
log('generateDocuments: $query');
|
|
|
|
final List<T?> error = [null];
|
|
print('Query: ${query is Document}');
|
|
final GetDocuments getDocuments = FreAccessWSGlobal.getDocuments;
|
|
final ApiCallResponse newItems = await getDocuments.call(pageKey, query);
|
|
|
|
if (newItems.jsonBody == null || newItems.jsonBody['error'] == true) {
|
|
return error;
|
|
}
|
|
|
|
final List<dynamic> list = newItems.jsonBody['value']['list'];
|
|
final List<Document> docs = list.map((item) {
|
|
log('-> generateDocuments: $item');
|
|
return Document(
|
|
id: item['id'],
|
|
description: item['description'],
|
|
type: item['type'],
|
|
category: Category(
|
|
id: item['category']['id'],
|
|
color: item['category']['color'].toColor(),
|
|
title: item['category']['description'],
|
|
),
|
|
person: item['person'] ?? '',
|
|
property: item['property'] ?? '',
|
|
createdAt: item['createdAt'],
|
|
updatedAt: item['updatedAt'],
|
|
);
|
|
}).toList();
|
|
|
|
return docs as List<T?>;
|
|
}
|
|
|
|
/// [generateHeaderItems]
|
|
Future<List<T?>> generateHeaderItems<T extends Category>() async {
|
|
final List<T?> error = [null];
|
|
|
|
final GetCategories getCategories = FreAccessWSGlobal.getCategories;
|
|
final ApiCallResponse newItems = await getCategories.call();
|
|
|
|
if (newItems.jsonBody == null || newItems.jsonBody['error'] == true) {
|
|
return error;
|
|
}
|
|
|
|
final List<dynamic> list = newItems.jsonBody['value'];
|
|
final List<Category> categories = list.map((item) {
|
|
return Category(
|
|
id: item['id'],
|
|
color: item['color'].toColor(),
|
|
title: item['description'],
|
|
);
|
|
}).toList();
|
|
|
|
log('categories: $categories');
|
|
return categories as List<T?>;
|
|
}
|
|
|
|
/// [filter]
|
|
void filter<T>(T query, BuildContext context) {
|
|
context
|
|
.read<DocumentPageBloc>()
|
|
.add(FilterCategoryEvent(query as Archive?));
|
|
}
|
|
// {
|
|
// log('filterByCategories: ');
|
|
// final state = managerKey.currentState;
|
|
|
|
// if (state != null) {
|
|
// // safeSetState(() {
|
|
// // if (isCategorySelected) {
|
|
// // filter(null);
|
|
// // isCategorySelected = false;
|
|
// // } else {
|
|
// // filter(query);
|
|
// // isCategorySelected = true;
|
|
// // }
|
|
// // });
|
|
// }
|
|
// }
|
|
|
|
/// [onFetchError]
|
|
void onFetchError(Object e, StackTrace s) {
|
|
DialogUtil.errorDefault(viewerKey.currentContext!);
|
|
LogUtil.requestAPIFailed(
|
|
"proccessRequest.php", "", "Consulta de Veículo", e, s);
|
|
}
|
|
}
|