This commit is contained in:
jantunesmessias 2025-02-07 17:37:43 -03:00
parent 906fbcaf24
commit f193baebe7
2 changed files with 38 additions and 26 deletions

View File

@ -46,6 +46,8 @@ class _AccessHistoryState extends State<AccessHistoryScreen> {
selectedTypeSubject.listen((value) {}); selectedTypeSubject.listen((value) {});
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();

View File

@ -7,6 +7,8 @@ class VehicleHistoryScreen extends StatefulWidget {
VehicleHistoryScreen(this.model, {super.key}); VehicleHistoryScreen(this.model, {super.key});
late VehicleModel model; late VehicleModel model;
final scaffoldKey = GlobalKey<ScaffoldState>();
final builderKey = GlobalKey();
@override @override
State<VehicleHistoryScreen> createState() => _VehicleHistoryScreenState(); State<VehicleHistoryScreen> createState() => _VehicleHistoryScreenState();
@ -17,6 +19,11 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen>
with Remotable { with Remotable {
@override
void dispose() {
super.dispose();
_scrollController.dispose();
}
@override @override
void initState() { void initState() {
@ -31,19 +38,22 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen>
late final double limitedBodyTextSize = late final double limitedBodyTextSize =
LimitedFontSizeUtil.getBodyFontSize(context); LimitedFontSizeUtil.getBodyFontSize(context);
return Column( return Scaffold(
mainAxisSize: MainAxisSize.max, key: widget.scaffoldKey,
mainAxisAlignment: MainAxisAlignment.start, body: Column(
children: [ mainAxisSize: MainAxisSize.max,
if (_hasData == false && mainAxisAlignment: MainAxisAlignment.start,
_pageNumber <= 1 && children: [
_loading == false) if (_hasData == false &&
_buildNoDataFound(context, limitedHeaderTextSize) _pageNumber <= 1 &&
else if (_hasData == true || _pageNumber >= 1) _loading == false)
_buildHistoryList(context, limitedBodyTextSize), _buildNoDataFound(context, limitedHeaderTextSize)
if (_hasData == true && _loading == true) else if (_hasData == true || _pageNumber >= 1)
_buildLoadingIndicator(context), _buildHistoryList(context, limitedBodyTextSize),
].addToStart(const SizedBox(height: 0)), if (_hasData == true && _loading == true)
_buildLoadingIndicator(context),
].addToStart(const SizedBox(height: 0)),
),
); );
} }
@ -72,7 +82,7 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen>
Widget _buildHistoryList(BuildContext context, double limitedBodyTextSize) { Widget _buildHistoryList(BuildContext context, double limitedBodyTextSize) {
return Expanded( return Expanded(
child: FutureBuilder<List<dynamic>>( child: FutureBuilder<void>(
future: _fetch(), future: _fetch(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) { if (snapshot.connectionState == ConnectionState.waiting) {
@ -86,8 +96,8 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen>
restorationId: '', restorationId: '',
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
controller: _scrollController, controller: _scrollController,
itemCount: snapshot.data!.length , itemCount: _wrap.length,
itemBuilder: (context, index) => _generateItems(context, snapshot.data![index], index), itemBuilder: (context, index) => _generateItems(context, _wrap[index], index),
); );
} }
@ -124,8 +134,8 @@ mixin Remotable on State<VehicleHistoryScreen> {
bool _loading = true; bool _loading = true;
int count = 0; int count = 0;
Future<List<dynamic>> _fetch() async { Future<void> _fetch() async {
if (!_hasData || !_loading) return _wrap; if (!_hasData || !_loading) return;
print('hasHasData'); print('hasHasData');
setState(() => _loading = true); setState(() => _loading = true);
try { try {
@ -137,10 +147,10 @@ mixin Remotable on State<VehicleHistoryScreen> {
setState(() { setState(() {
_hasData = true; _hasData = true;
_loading = false; _loading = false;
_wrap.addAll(vehicles);
}); });
print('vehicles.isNotEmpty');
_wrap.addAll(vehicles); return;
return _wrap;
} }
_showNoMoreDataSnackBar(context); _showNoMoreDataSnackBar(context);
@ -151,7 +161,7 @@ mixin Remotable on State<VehicleHistoryScreen> {
}); });
print('hasEmpty: ${_wrap.length}'); print('hasEmpty: ${_wrap.length}');
return _wrap; return;
} catch (e, s) { } catch (e, s) {
DialogUtil.errorDefault(context); DialogUtil.errorDefault(context);
LogUtil.requestAPIFailed("proccessRequest.php", "", "Consulta de Veículo", e, s); LogUtil.requestAPIFailed("proccessRequest.php", "", "Consulta de Veículo", e, s);
@ -160,7 +170,7 @@ mixin Remotable on State<VehicleHistoryScreen> {
_loading = false; _loading = false;
}); });
print('hasError'); print('hasError');
return _wrap; return;
} }
} }
@ -291,10 +301,10 @@ mixin Remotable on State<VehicleHistoryScreen> {
offset = _scrollController.offset; offset = _scrollController.offset;
_loadMore(); _loadMore();
} }
}); },);
} }
void _loadMore() async { void _loadMore() {
if (_hasData) { if (_hasData) {
_pageNumber+=1; _pageNumber+=1;
_loading = true; _loading = true;