part of 'index.dart'; class DocumentPageModel extends FlutterFlowModel { DocumentPageModel._privateConstructor(); static final DocumentPageModel _instance = DocumentPageModel._privateConstructor(); factory DocumentPageModel() { return _instance; } late EnhancedListViewKey vihicleScreenManager; late DocumentKey vehicleScreenViewer; late PagingController _pagingController; /// ------------ @override void initState(BuildContext context) { vihicleScreenManager = EnhancedListViewKey(); vehicleScreenViewer = DocumentKey(); _pagingController = PagingController(firstPageKey: 1); } @override void dispose() { _pagingController.dispose(); vihicleScreenManager.currentState?.dispose(); vehicleScreenViewer.currentState?.dispose(); } /// ------------ /// [onView] void onView(Document document, BuildContext context) async { context.read().add(SelectDocumentEvent(document)); } /// [itemBodyBuilder] DocumentItem itemBodyBuilder( BuildContext context, T item, int index) { print('ItemBuilder -> $index'); return DocumentItem( document: item, onPressed: onView, ); } CategoryItem categoryItemBuilder(T? item) { return CategoryItem(category: item! as Category); } /// [itemHeaderBuilder] Widget itemHeaderBuilder(Future> 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( generateItems: gen, itemBuilder: categoryItemBuilder, filter: filter, ), ], ); }); /// [generateBodyItems] Future> generateBodyItems( int pageKey, int pageSize, dynamic query) async { log('generateDocuments: $query'); final List error = [null]; print('Query: ${query is Document}'); final GetDocuments getDocuments = FreAccessWSGlobal.getDocuments; final ApiCallResponse newItems = await getDocuments.call(pageKey, query); if (newItems.jsonBody == null) return error; if (newItems.jsonBody['error'] == true) return error; final List list = newItems.jsonBody['value']['list']; late final List docs = []; for (var item in list) { log('-> generateDocuments: $item'); final String description = item['description']; final String type = item['type']; final String category = item['category']['description']; final String color = item['category']['color']; final String person = item['person'] ?? ''; final String property = item['property'] ?? ''; final String createdAt = item['createdAt']; final String updatedAt = item['updatedAt']; final int categoryId = item['category']['id']; final int documentId = item['id']; final doc = Document( id: documentId, description: description, type: type, category: Category( id: categoryId, color: color.toColor(), title: category, ), person: person, property: property, createdAt: createdAt, updatedAt: updatedAt, ); docs.add(doc); } return docs as List; } /// [generateHeaderItems] Future> generateHeaderItems() async { log('generateCategories: '); final List error = [null]; final GetCategories getCategories = FreAccessWSGlobal.getCategories; final ApiCallResponse newItems = await getCategories.call(); if (newItems.jsonBody['error'] == true) return error; if (newItems.jsonBody == null) return error; final list = newItems.jsonBody['value'] as List; late final List cats = []; for (var item in list) { final String color = item['color']; final String title = item['description']; final int id = item['id']; final cat = Category( id: id, color: color.toColor(), title: title, ); cats.add(cat); } log('cats: $cats'); return cats as List; } /// [filter] void filter(T query, BuildContext context) { context .read() .add(FilterCategoryEvent(query as Archive?)); } /// [onFetchError] void onFetchError(Object e, StackTrace s) { DialogUtil.errorDefault(vehicleScreenViewer.currentContext!); LogUtil.requestAPIFailed( "proccessRequest.php", "", "Consulta de Veículo", e, s); } }