diff --git a/lib/core/index.dart b/lib/core/index.dart deleted file mode 100644 index 8b137891..00000000 --- a/lib/core/index.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/core/meta/anotations.dart b/lib/core/meta/anotations.dart deleted file mode 100644 index 842e5064..00000000 --- a/lib/core/meta/anotations.dart +++ /dev/null @@ -1,5 +0,0 @@ -class DeadCode { - final String? desc; - - const DeadCode([this.desc = '']); -} diff --git a/lib/core/meta/index.dart b/lib/core/meta/index.dart deleted file mode 100644 index 166d574c..00000000 --- a/lib/core/meta/index.dart +++ /dev/null @@ -1 +0,0 @@ -export 'anotations.dart'; diff --git a/lib/flutter_flow/flutter_flow_util.dart b/lib/flutter_flow/flutter_flow_util.dart index bcb34fe5..b86d9da4 100644 --- a/lib/flutter_flow/flutter_flow_util.dart +++ b/lib/flutter_flow/flutter_flow_util.dart @@ -785,3 +785,5 @@ double computeGradientAlignmentY(double evaluatedAngle) { } return double.parse(roundTo(y, 2)); } + + diff --git a/lib/initialization.dart b/lib/initialization.dart index d282e961..1d50273e 100644 --- a/lib/initialization.dart +++ b/lib/initialization.dart @@ -56,6 +56,8 @@ Future _initializeSystemSettings() async { if (kDebugMode) { //kDebugMode print('Debug mode'); + } else { + print('Release mode'); bool unsentReports = await FirebaseCrashlytics.instance.checkForUnsentReports(); if (unsentReports) { @@ -66,9 +68,6 @@ Future _initializeSystemSettings() async { // Não existem relatórios não enviados print('Todos os relatórios de falhas foram enviados.'); } - } else { - print('Release mode'); - await crashlyticsInstance.setCrashlyticsCollectionEnabled(true); // if (crashlyticsInstance.isCrashlyticsCollectionEnabled) { FlutterError.onError = await crashlyticsInstance.recordFlutterError; diff --git a/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart b/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart index a53747a3..4f6c6bdf 100644 --- a/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart +++ b/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart @@ -4,7 +4,6 @@ part of 'vehicles_on_the_property.dart'; // ignore: must_be_immutable class VehicleHistoryScreen extends StatefulWidget { - VehicleHistoryScreen(this.model, {super.key}); late VehicleModel model; final scaffoldKey = GlobalKey(); @@ -12,23 +11,21 @@ class VehicleHistoryScreen extends StatefulWidget { @override State createState() => _VehicleHistoryScreenState(); - } class _VehicleHistoryScreenState extends State with Remotable { - - @override void dispose() { super.dispose(); - _scrollController.dispose(); + _pagingController.dispose(); } @override void initState() { super.initState(); _initializeScrollController(); + _pagingController.addPageRequestListener(_fetch); } @override @@ -38,22 +35,19 @@ class _VehicleHistoryScreenState extends State late final double limitedBodyTextSize = LimitedFontSizeUtil.getBodyFontSize(context); - return Scaffold( - key: widget.scaffoldKey, - body: Column( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - if (_hasData == false && - _pageNumber <= 1 && - _loading == false) - _buildNoDataFound(context, limitedHeaderTextSize) - else if (_hasData == true || _pageNumber >= 1) - _buildHistoryList(context, limitedBodyTextSize), - if (_hasData == true && _loading == true) - _buildLoadingIndicator(context), - ].addToStart(const SizedBox(height: 0)), - ), + return Column( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + // if (_hasData == false && + // _pageNumber <= 1 && + // _loading == false) + // _buildNoDataFound(context, limitedHeaderTextSize) + // else if (_hasData == true || _pageNumber >= 1) + _buildHistoryList(context, limitedBodyTextSize), + // if (_hasData == true && _loading == true) + // _buildLoadingIndicator(context), + ].addToStart(const SizedBox(height: 0)), ); } @@ -82,30 +76,34 @@ class _VehicleHistoryScreenState extends State Widget _buildHistoryList(BuildContext context, double limitedBodyTextSize) { return Expanded( - child: FutureBuilder( - future: _fetch(), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return Center(child: CircularProgressIndicator()); - } else if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); - } else { - return ListView.builder( - shrinkWrap: true, - addAutomaticKeepAlives: true, - restorationId: '', - physics: const BouncingScrollPhysics(), - controller: _scrollController, - itemCount: _wrap.length, - itemBuilder: (context, index) => _generateItems(context, _wrap[index], index), - - ); - } - }, + child: RefreshIndicator( + onRefresh: () async => _pagingController.refresh(), + child: PagedListView( + // separatorBuilder: (context, index) => const Divider(), + pagingController: _pagingController, + builderDelegate: PagedChildBuilderDelegate( + animateTransitions: true, + itemBuilder: (context, item, index) => + _generateItems(context, index, item), + firstPageErrorIndicatorBuilder: (context) => Placeholder(), + newPageErrorIndicatorBuilder: (context) => Placeholder(), + ), + ), ), ); } + // ListView.builder( + // shrinkWrap: true, + // addAutomaticKeepAlives: true, + // restorationId: '', + // physics: const BouncingScrollPhysics(), + // controller: _scrollController, + // itemCount: _wrap.length, + // itemBuilder: (context, index) => _generateItems(context, _wrap[index], index), + + // ), + Widget _buildLoadingIndicator(BuildContext context) { return Container( padding: const EdgeInsets.only(top: 15, bottom: 15), @@ -118,15 +116,13 @@ class _VehicleHistoryScreenState extends State ), ); } - - - } - mixin Remotable on State { + final PagingController _pagingController = + PagingController(firstPageKey: 1); - late ScrollController _scrollController; + // late ScrollController _scrollController; double offset = 0.0; List _wrap = []; int _pageNumber = 1; @@ -134,37 +130,46 @@ mixin Remotable on State { bool _loading = true; int count = 0; - Future _fetch() async { + Future _fetch(dynamic pageKey) async { if (!_hasData || !_loading) return; print('hasHasData'); - setState(() => _loading = true); + // setState(() => _loading = true); try { + var newItems = + await PhpGroup.getVehiclesByProperty.call(pageKey.toString()); + final bool isLastPage = newItems.jsonBody == null || + newItems.jsonBody == [] || + newItems.jsonBody == ''; - var response = await PhpGroup.getVehiclesByProperty.call(_pageNumber.toString()); - final List vehicles = response.jsonBody['vehicles'] as List? ?? []; - safeSetState(() => count = response.jsonBody['total_rows'] ?? 0); - if (vehicles.isNotEmpty) { + if (newItems.jsonBody == null) { + } else { + final List vehicles = + newItems.jsonBody['vehicles'] as List? ?? []; + _pagingController.nextPageKey = pageKey + 1; + + safeSetState(() => count = newItems.jsonBody['total_rows'] ?? 0); + if (vehicles.isNotEmpty) { + // setState(() { + // _hasData = true; + // _loading = false; + // _wrap.addAll(vehicles); + // }); + _pagingController.appendLastPage(vehicles); + + return; + } + _showNoMoreDataSnackBar(context); setState(() { - _hasData = true; + _hasData = false; _loading = false; - _wrap.addAll(vehicles); }); - + print('hasEmpty: ${_wrap.length}'); return; } - - _showNoMoreDataSnackBar(context); - - setState(() { - _hasData = false; - _loading = false; - }); - - print('hasEmpty: ${_wrap.length}'); - return; } catch (e, s) { DialogUtil.errorDefault(context); - LogUtil.requestAPIFailed("proccessRequest.php", "", "Consulta de Veículo", e, s); + LogUtil.requestAPIFailed( + "proccessRequest.php", "", "Consulta de Veículo", e, s); setState(() { _hasData = false; _loading = false; @@ -202,37 +207,48 @@ mixin Remotable on State { ); } - Widget? _generateItems(BuildContext context, dynamic snapshot, int index) { - if (index == 0) return _buildHeader(context); - - final bool? isOwner = snapshot['isOwnerVehicle']; - final IconData? iconData = isOwner == true ? Symbols.garage : Symbols.directions_car; - final FreCardIcon? cardIcon = isOwner != null - ? FreCardIcon(height: 50, width: 100, icon: Icon(iconData, size: 80, opticalSize: 10)) - : null; + Widget _generateItems(BuildContext context, int index, dynamic item) { + log('item: $item'); - final String? tag = snapshot['tag']; - final bool containTag = tag.isNotNullAndEmpty; - final Map labelsHashMap = _generateLabelsHashMap(context, snapshot, tag, containTag); + // return Placeholder(); - final List> statusHashMapList = _generateStatusHashMapList(snapshot); + // if (index == 0) return _buildHeader(context); - Future onTapCardItemAction() async { - _handleCardItemTap(context, cardIcon, snapshot); - } + final bool? isOwner = item['isOwnerVehicle']; + final IconData? iconData = + isOwner == true ? Symbols.garage : Symbols.directions_car; + final FreCardIcon? cardIcon = isOwner != null + ? FreCardIcon( + height: 50, + width: 100, + icon: Icon(iconData, size: 80, opticalSize: 10)) + : null; - final statusLinkedHashMap = statusHashMapList.map((map) => LinkedHashMap.from(map)).toList(); - final length = statusLinkedHashMap.expand((e) => [e.length]); + final String? tag = item['tag']; + final bool containTag = tag.isNotNullAndEmpty; + final Map labelsHashMap = + _generateLabelsHashMap(context, item, tag, containTag); - return CardItemTemplateComponentWidget( - icon: cardIcon, - labelsHashMap: labelsHashMap, - statusHashMap: statusHashMapList, - onTapCardItemAction: onTapCardItemAction, - itemWidthFactor: length == 1 ? 0.25 : 0.50, - ); + final List> statusHashMapList = + _generateStatusHashMapList(item); + + Future onTapCardItemAction() async { + _handleCardItemTap(context, cardIcon, item); } - + + final statusLinkedHashMap = statusHashMapList + .map((map) => LinkedHashMap.from(map)) + .toList(); + final length = statusLinkedHashMap.expand((e) => [e.length]); + + return CardItemTemplateComponentWidget( + icon: cardIcon, + labelsHashMap: labelsHashMap, + statusHashMap: statusHashMapList, + onTapCardItemAction: onTapCardItemAction, + itemWidthFactor: length == 1 ? 0.25 : 0.50, + ); + } Map _generateLabelsHashMap(BuildContext context, Map uItem, String? tag, bool containTag) { @@ -249,17 +265,16 @@ mixin Remotable on State { }; } - List> _generateStatusHashMapList( - Map uItem) { - final statusHashMap = - widget.model.generateStatusColorMap(uItem, false); + List> _generateStatusHashMapList( + Map uItem) { + final statusHashMap = widget.model.generateStatusColorMap(uItem, false); return statusHashMap != null ? [statusHashMap] : []; } Future _handleCardItemTap(BuildContext context, FreCardIcon? cardIcon, Map uItem) async { try { - final dialogContent = widget.model.buildVehicleDetails( + final dialogContent = widget.model.buildVehicleDetails( icon: cardIcon, item: uItem, context: context, @@ -274,7 +289,7 @@ mixin Remotable on State { ).whenComplete(() { safeSetState(() { _pageNumber = 1; - _fetch(); + _fetch(1); }); }); } catch (e, s) { @@ -289,27 +304,26 @@ mixin Remotable on State { } void _initializeScrollController() { - _scrollController = ScrollController(keepScrollOffset: true, initialScrollOffset: offset) - ..addListener(() { - print('ScrollController'); - if(!_hasData) return; - if - // (_scrollController.position.pixels >= _scrollController.position.maxScrollExtent) - (_scrollController.position.atEdge && _scrollController.position.pixels != 0) - { - print('ScrollController -> loadMore'); - offset = _scrollController.offset; - _loadMore(); - } - },); - } - - void _loadMore() { - if (_hasData) { - _pageNumber+=1; - _loading = true; - _fetch(); - } + // _scrollController = ScrollController(keepScrollOffset: true, initialScrollOffset: offset) + // ..addListener(() { + // print('ScrollController'); + // if(!_hasData) return; + // if + // // (_scrollController.position.pixels >= _scrollController.position.maxScrollExtent) + // (_scrollController.position.atEdge && _scrollController.position.pixels != 0) + // { + // print('ScrollController -> loadMore'); + // offset = _scrollController.offset; + // _loadMore(); + // } + // },); } + // void _loadMore() { + // if (_hasData) { + // _pageNumber+=1; + // _loading = true; + // _fetch(_pageNumber); + // } + // } } diff --git a/lib/pages/vehicles_on_the_property/vehicles_on_the_property.dart b/lib/pages/vehicles_on_the_property/vehicles_on_the_property.dart index f23ccb38..174519fb 100644 --- a/lib/pages/vehicles_on_the_property/vehicles_on_the_property.dart +++ b/lib/pages/vehicles_on_the_property/vehicles_on_the_property.dart @@ -16,6 +16,7 @@ import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/license_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; import 'package:hub/shared/utils/log_util.dart'; +import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:material_symbols_icons/symbols.dart'; part 'vehicle_history_screen.dart'; diff --git a/lib/shared/index.dart b/lib/shared/index.dart deleted file mode 100644 index 8b137891..00000000 --- a/lib/shared/index.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/pubspec.yaml b/pubspec.yaml index 26ed4273..b78ebdf7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,6 +15,7 @@ dependencies: sdk: flutter auto_size_text: 3.0.0 barcode_widget: ^2.0.4 + infinite_scroll_pagination: ^4.1.0 cached_network_image: ^3.4.0 firebase_core: ^3.4.0 flutter_inappwebview: ^6.0.0 @@ -103,7 +104,25 @@ dependencies: # crypto: ^3.0.5 freezed_annotation: ^2.4.4 package_info_plus: ^8.1.1 + sliver_tools: ^0.2.12 # json_annotation: ^4.9.0 + base: + git: + url: 'git@github.com:FRE-Informatica/flutter-freaccess-base.git' + path: 'packages/base' + components: + git: + url: 'git@github.com:FRE-Informatica/flutter-freaccess-base.git' + path: 'packages/components' + templates: + git: + url: 'git@github.com:FRE-Informatica/flutter-freaccess-base.git' + path: 'packages/templates' + theme: + git: + url: 'git@github.com:FRE-Informatica/flutter-freaccess-base.git' + path: 'packages/theme' + dependency_overrides: http: 1.2.1