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) {});
}
@override
void initState() {
super.initState();

View File

@ -7,6 +7,8 @@ class VehicleHistoryScreen extends StatefulWidget {
VehicleHistoryScreen(this.model, {super.key});
late VehicleModel model;
final scaffoldKey = GlobalKey<ScaffoldState>();
final builderKey = GlobalKey();
@override
State<VehicleHistoryScreen> createState() => _VehicleHistoryScreenState();
@ -17,6 +19,11 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen>
with Remotable {
@override
void dispose() {
super.dispose();
_scrollController.dispose();
}
@override
void initState() {
@ -31,19 +38,22 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen>
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<VehicleHistoryScreen>
Widget _buildHistoryList(BuildContext context, double limitedBodyTextSize) {
return Expanded(
child: FutureBuilder<List<dynamic>>(
child: FutureBuilder<void>(
future: _fetch(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
@ -86,9 +96,9 @@ class _VehicleHistoryScreenState extends State<VehicleHistoryScreen>
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<VehicleHistoryScreen> {
bool _loading = true;
int count = 0;
Future<List<dynamic>> _fetch() async {
if (!_hasData || !_loading) return _wrap;
Future<void> _fetch() async {
if (!_hasData || !_loading) return;
print('hasHasData');
setState(() => _loading = true);
try {
@ -137,10 +147,10 @@ mixin Remotable on State<VehicleHistoryScreen> {
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<VehicleHistoryScreen> {
});
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<VehicleHistoryScreen> {
_loading = false;
});
print('hasError');
return _wrap;
return;
}
}
@ -291,10 +301,10 @@ mixin Remotable on State<VehicleHistoryScreen> {
offset = _scrollController.offset;
_loadMore();
}
});
},);
}
void _loadMore() async {
void _loadMore() {
if (_hasData) {
_pageNumber+=1;
_loading = true;