diff --git a/lib/features/history/presentation/pages/acess_history_page_widget.dart b/lib/features/history/presentation/pages/acess_history_page_widget.dart index b855ec30..bb6a8891 100644 --- a/lib/features/history/presentation/pages/acess_history_page_widget.dart +++ b/lib/features/history/presentation/pages/acess_history_page_widget.dart @@ -46,6 +46,8 @@ class _AccessHistoryState extends State { selectedTypeSubject.listen((value) {}); } + + @override void initState() { super.initState(); 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 f6878016..a53747a3 100644 --- a/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart +++ b/lib/pages/vehicles_on_the_property/vehicle_history_screen.dart @@ -7,6 +7,8 @@ class VehicleHistoryScreen extends StatefulWidget { VehicleHistoryScreen(this.model, {super.key}); late VehicleModel model; + final scaffoldKey = GlobalKey(); + final builderKey = GlobalKey(); @override State createState() => _VehicleHistoryScreenState(); @@ -17,6 +19,11 @@ class _VehicleHistoryScreenState extends State with Remotable { + @override + void dispose() { + super.dispose(); + _scrollController.dispose(); + } @override void initState() { @@ -31,19 +38,22 @@ class _VehicleHistoryScreenState extends State late final double limitedBodyTextSize = LimitedFontSizeUtil.getBodyFontSize(context); - 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)), + 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)), + ), ); } @@ -72,7 +82,7 @@ class _VehicleHistoryScreenState extends State Widget _buildHistoryList(BuildContext context, double limitedBodyTextSize) { return Expanded( - child: FutureBuilder>( + child: FutureBuilder( future: _fetch(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { @@ -86,9 +96,9 @@ class _VehicleHistoryScreenState extends State restorationId: '', physics: const BouncingScrollPhysics(), controller: _scrollController, - itemCount: snapshot.data!.length , - itemBuilder: (context, index) => _generateItems(context, snapshot.data![index], index), - + itemCount: _wrap.length, + itemBuilder: (context, index) => _generateItems(context, _wrap[index], index), + ); } }, @@ -124,8 +134,8 @@ mixin Remotable on State { bool _loading = true; int count = 0; - Future> _fetch() async { - if (!_hasData || !_loading) return _wrap; + Future _fetch() async { + if (!_hasData || !_loading) return; print('hasHasData'); setState(() => _loading = true); try { @@ -137,10 +147,10 @@ mixin Remotable on State { setState(() { _hasData = true; _loading = false; + _wrap.addAll(vehicles); }); - print('vehicles.isNotEmpty'); - _wrap.addAll(vehicles); - return _wrap; + + return; } _showNoMoreDataSnackBar(context); @@ -151,7 +161,7 @@ mixin Remotable on State { }); print('hasEmpty: ${_wrap.length}'); - return _wrap; + return; } catch (e, s) { DialogUtil.errorDefault(context); LogUtil.requestAPIFailed("proccessRequest.php", "", "Consulta de VeĆ­culo", e, s); @@ -160,7 +170,7 @@ mixin Remotable on State { _loading = false; }); print('hasError'); - return _wrap; + return; } } @@ -291,10 +301,10 @@ mixin Remotable on State { offset = _scrollController.offset; _loadMore(); } - }); + },); } - void _loadMore() async { + void _loadMore() { if (_hasData) { _pageNumber+=1; _loading = true;