278 lines
8.9 KiB
Dart
278 lines
8.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hub/actions/actions.dart';
|
|
import 'package:hub/backend/api_requests/api_calls.dart';
|
|
import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart';
|
|
import 'package:hub/components/templates_components/details_component/details_component_action.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
|
|
import 'package:hub/flutter_flow/flutter_flow_util.dart';
|
|
import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart';
|
|
import 'package:hub/shared/utils/dialog_util.dart';
|
|
import 'package:hub/shared/utils/log_util.dart';
|
|
import 'package:hub/shared/utils/validator_util.dart';
|
|
|
|
class PetsHistoryScreen extends StatefulWidget {
|
|
PetsHistoryScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_PetsHistoryScreenState createState() => _PetsHistoryScreenState();
|
|
}
|
|
|
|
class _PetsHistoryScreenState extends State<PetsHistoryScreen>
|
|
with TickerProviderStateMixin {
|
|
late ScrollController _scrollController;
|
|
int _pageNumber = 1;
|
|
final int _pageSize = 10;
|
|
bool _hasData = false;
|
|
bool _loading = false;
|
|
int count = 0;
|
|
|
|
late Future<void> _petsFuture;
|
|
List<dynamic> _petsWrap = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_petsFuture = _fetchVisits();
|
|
|
|
_scrollController = ScrollController()
|
|
..addListener(() {
|
|
if (_scrollController.position.atEdge &&
|
|
_scrollController.position.pixels != 0) {
|
|
_loadMore();
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_scrollController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<ApiCallResponse?> _fetchVisits() async {
|
|
try {
|
|
setState(() => _loading = true);
|
|
|
|
var response = await PhpGroup.getPets.call(
|
|
devUUID: AppState().devUUID,
|
|
userUUID: AppState().userUUID,
|
|
cliID: AppState().cliUUID,
|
|
atividade: 'consultaPets',
|
|
pageSize: _pageSize,
|
|
page: _pageNumber,
|
|
);
|
|
|
|
final List<dynamic> pets = response.jsonBody['pets']['list'] ?? [];
|
|
safeSetState(() => count = response.jsonBody['pets']['count'] ?? 0);
|
|
|
|
if (pets != null && pets.isNotEmpty) {
|
|
setState(() {
|
|
_petsWrap.addAll(pets);
|
|
_hasData = true;
|
|
_loading = false;
|
|
});
|
|
|
|
return response;
|
|
}
|
|
|
|
_showNoMoreDataSnackBar(context);
|
|
|
|
setState(() {
|
|
_hasData = false;
|
|
_loading = false;
|
|
});
|
|
|
|
return null;
|
|
} catch (e, s) {
|
|
DialogUtil.errorDefault(context);
|
|
LogUtil.requestAPIFailed(
|
|
"proccessRequest.php", "", "Consulta de Pets", e, s);
|
|
setState(() {
|
|
_hasData = false;
|
|
_loading = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
void _loadMore() {
|
|
if (_hasData == true) {
|
|
_pageNumber++;
|
|
|
|
_petsFuture = _fetchVisits();
|
|
}
|
|
}
|
|
|
|
void _showNoMoreDataSnackBar(BuildContext context) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: "Não há mais dados.", enText: "No more data."),
|
|
),
|
|
duration: const Duration(seconds: 3),
|
|
backgroundColor: FlutterFlowTheme.of(context).primary,
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
if (_hasData == false && _pageNumber <= 1 && _loading == false)
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: [
|
|
Center(
|
|
child: Text(FFLocalizations.of(context).getVariableText(
|
|
ptText: "Nenhum Pet encontrado!",
|
|
enText: "No pets found")),
|
|
)
|
|
],
|
|
),
|
|
)
|
|
else if (_hasData == true || _pageNumber >= 1)
|
|
Expanded(
|
|
child: FutureBuilder<void>(
|
|
future: _petsFuture,
|
|
builder: (context, snapshot) {
|
|
return ListView.builder(
|
|
shrinkWrap: true,
|
|
physics: const BouncingScrollPhysics(),
|
|
controller: _scrollController,
|
|
itemCount: _petsWrap.length + 1,
|
|
itemBuilder: (context, index) {
|
|
if (index == 0) {
|
|
// Add your item here
|
|
return Padding(
|
|
padding: EdgeInsets.only(right: 30, top: 10),
|
|
child: Text(
|
|
AppState().petAmountRegister == 0
|
|
? FFLocalizations.of(context).getVariableText(
|
|
ptText: "Ilimitado", enText: "Unlimited")
|
|
: "${FFLocalizations.of(context).getVariableText(ptText: "Quantidade de Pets: ", enText: "Amount of Pets: ")}${count}/${AppState().petAmountRegister}",
|
|
textAlign: TextAlign.right,
|
|
),
|
|
);
|
|
} else {
|
|
final item = _petsWrap[index - 1];
|
|
return _item(context, item);
|
|
}
|
|
});
|
|
},
|
|
)),
|
|
if (_hasData == true && _loading == true)
|
|
Container(
|
|
padding: const EdgeInsets.only(top: 15, bottom: 15),
|
|
child: Center(
|
|
child: CircularProgressIndicator(
|
|
valueColor: AlwaysStoppedAnimation<Color>(
|
|
FlutterFlowTheme.of(context).primary,
|
|
),
|
|
),
|
|
),
|
|
)
|
|
].addToStart(const SizedBox(height: 0)),
|
|
);
|
|
}
|
|
|
|
Widget _item(BuildContext context, dynamic uItem) {
|
|
return CardItemTemplateComponentWidget(
|
|
imagePath:
|
|
'https://freaccess.com.br/freaccess/getImage.php?devUUID=${AppState().devUUID}&userUUID=${AppState().userUUID}&cliID=${AppState().cliUUID}&atividade=consultaFotoPet&petId=${uItem['id'] ?? ''}',
|
|
labelsHashMap: {
|
|
'${FFLocalizations.of(context).getVariableText(ptText: "Nome", enText: "Name")}:':
|
|
uItem['name'] ?? '',
|
|
'${FFLocalizations.of(context).getVariableText(ptText: "Espécie", enText: "Species")}:':
|
|
uItem['species'] ?? '',
|
|
'${FFLocalizations.of(context).getVariableText(ptText: "Raça", enText: "Breed")}:':
|
|
uItem['breed'] ?? '',
|
|
},
|
|
statusHashMap: [
|
|
if (uItem['size'] == "MIN")
|
|
{
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Mini',
|
|
enText: 'Mini',
|
|
): FlutterFlowTheme.of(context).accent4,
|
|
},
|
|
if (uItem['size'] == "PEQ")
|
|
{
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Pequeno',
|
|
enText: 'Small',
|
|
): FlutterFlowTheme.of(context).accent4,
|
|
},
|
|
if (uItem['size'] == "MED")
|
|
{
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Medio',
|
|
enText: 'Medium',
|
|
): FlutterFlowTheme.of(context).accent4,
|
|
},
|
|
if (uItem['size'] == "GRA")
|
|
{
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Grande',
|
|
enText: 'Big',
|
|
): FlutterFlowTheme.of(context).accent4,
|
|
},
|
|
if (uItem['size'] == "GIG")
|
|
{
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Gigante',
|
|
enText: 'Giant',
|
|
): FlutterFlowTheme.of(context).accent4,
|
|
},
|
|
if (uItem['gender'] == "MAC")
|
|
{
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Macho', enText: 'Male'): Color(0xFF094CB0),
|
|
},
|
|
if (uItem['gender'] == "FEM")
|
|
{
|
|
FFLocalizations.of(context).getVariableText(
|
|
ptText: 'Femêa',
|
|
enText: 'Female',
|
|
): Color(0xFFE463E7),
|
|
}
|
|
],
|
|
onTapCardItemAction: () async {
|
|
await showDialog(
|
|
useSafeArea: true,
|
|
context: context,
|
|
builder: (context) {
|
|
return Dialog(
|
|
alignment: Alignment.center,
|
|
child: buildPetDetails(
|
|
uItem,
|
|
context,
|
|
changeStatusAction,
|
|
),
|
|
);
|
|
},
|
|
).whenComplete(() {
|
|
safeSetState(() {
|
|
_pageNumber = 1;
|
|
_petsWrap = [];
|
|
_petsFuture =
|
|
_fetchVisits().then((value) => value!.jsonBody['pets'] ?? []);
|
|
});
|
|
}).catchError((e, s) {
|
|
DialogUtil.errorDefault(context);
|
|
LogUtil.requestAPIFailed(
|
|
"proccessRequest.php", "", "Consulta de Pets", e, s);
|
|
safeSetState(() {
|
|
_hasData = false;
|
|
_loading = false;
|
|
});
|
|
});
|
|
},
|
|
);
|
|
}
|
|
}
|