fix visitorRegister and visitHIstory

This commit is contained in:
jantunesmesias 2024-08-09 09:38:33 -03:00
parent 016be1df54
commit bc1c684d72
7 changed files with 350 additions and 356 deletions

View File

@ -1417,53 +1417,39 @@ class PostProvVisitSchedulingCall {
} }
class GetVisitsCall { class GetVisitsCall {
Stream<ApiCallResponse> call({ Future<ApiCallResponse> call({
String? devUUID = '', String? devUUID = '',
String? userUUID = '', String? userUUID = '',
String? cliID = '', String? cliID = '',
String? atividade = '', String? atividade = '',
int? pageSize, int? pageSize,
int? pageNumber, int? pageNumber,
}) { }) async {
final baseUrl = PhpGroup.getBaseUrl(); final baseUrl = PhpGroup.getBaseUrl();
final StreamController<ApiCallResponse> controller = StreamController();
Future.microtask( return ApiManager.instance.makeApiCall(
() async { callName: 'getVisits',
try { apiUrl: '$baseUrl/processRequest.php',
final response = await ApiManager.instance.makeApiCall( callType: ApiCallType.POST,
callName: 'getVisits', headers: {
apiUrl: '$baseUrl/processRequest.php', 'Content-Type': 'application/x-www-form-urlencoded',
callType: ApiCallType.POST,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
params: {
'devUUID': devUUID,
'userUUID': userUUID,
'cliID': cliID,
'atividade': atividade,
'pageSize': pageSize,
'pageNumber': pageNumber,
},
bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
returnBody: true,
encodeBodyUtf8: false,
decodeUtf8: false,
cache: false,
isStreamingApi: false,
alwaysAllowBody: false,
);
controller.add(response);
controller.close();
} catch (e) {
controller.addError(e);
controller.close();
}
}, },
params: {
'devUUID': devUUID,
'userUUID': userUUID,
'cliID': cliID,
'atividade': atividade,
'pageSize': pageSize,
'pageNumber': pageNumber,
},
bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
returnBody: true,
encodeBodyUtf8: false,
decodeUtf8: false,
cache: false,
isStreamingApi: false,
alwaysAllowBody: false,
); );
return controller.stream;
} }
bool? error(dynamic response) => castToType<bool>(getJsonField( bool? error(dynamic response) => castToType<bool>(getJsonField(

View File

@ -44,7 +44,7 @@ Widget buildDetails(
visitaWrapItem['VTE_DOCUMENTO'] ?? '', visitaWrapItem['VTE_DOCUMENTO'] ?? '',
) )
.then((value) { .then((value) {
Navigator.pop(context); Navigator.pop(context, value);
if (value == false) { if (value == false) {
showSnackbar( showSnackbar(
context, context,

View File

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:developer'; import 'dart:developer';
import 'package:hub/components/molecular_components/throw_exception/throw_exception_widget.dart'; import 'package:hub/components/molecular_components/throw_exception/throw_exception_widget.dart';
@ -14,12 +15,20 @@ import 'regisiter_vistor_template_component_widget.dart';
class RegisiterVistorTemplateComponentModel class RegisiterVistorTemplateComponentModel
extends FlutterFlowModel<RegisiterVistorTemplateComponentWidget> { extends FlutterFlowModel<RegisiterVistorTemplateComponentWidget> {
/// State fields for stateful widgets in this page. /// State fields for stateful widgets in this page.
Timer? _debounceTimer;
final unfocusNode = FocusNode(); final unfocusNode = FocusNode();
bool isDataUploading = false; bool isDataUploading = false;
FFUploadedFile uploadedLocalFile = FFUploadedFile uploadedLocalFile =
FFUploadedFile(bytes: Uint8List.fromList([])); FFUploadedFile(bytes: Uint8List.fromList([]));
void debounce(Function() fn, Duration time) {
if (_debounceTimer != null) {
_debounceTimer!.cancel();
}
_debounceTimer = Timer(time, fn);
}
// State field(s) for TextField widget. // State field(s) for TextField widget.
FocusNode? textFieldFocusNode1; FocusNode? textFieldFocusNode1;
TextEditingController? textController1; TextEditingController? textController1;
@ -35,7 +44,7 @@ class RegisiterVistorTemplateComponentModel
return null; return null;
} }
Future<bool?> getVisitanteByDocument( Future<bool> getVisitanteByDocument(
String document, BuildContext context) async { String document, BuildContext context) async {
final response = await PhpGroup.getVisitorByDocCall.call( final response = await PhpGroup.getVisitorByDocCall.call(
devUUID: FFAppState().devUUID, devUUID: FFAppState().devUUID,
@ -49,7 +58,7 @@ class RegisiterVistorTemplateComponentModel
response.jsonBody['error'] != 'false') { response.jsonBody['error'] != 'false') {
return true; return true;
} }
return null; return false;
} }
// State field(s) for TextField widget. // State field(s) for TextField widget.

View File

@ -39,10 +39,14 @@ class _RegisiterVistorTemplateComponentWidgetState
final scaffoldKey = GlobalKey<ScaffoldState>(); final scaffoldKey = GlobalKey<ScaffoldState>();
bool _isVisitorRegistered = false; bool _isVisitorRegistered = false;
BehaviorSubject<bool> visitorAlreadyRegistered = BehaviorSubject<bool>();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
visitorAlreadyRegistered = BehaviorSubject<bool>.seeded(false);
_model = _model =
createModel(context, () => RegisiterVistorTemplateComponentModel()); createModel(context, () => RegisiterVistorTemplateComponentModel());
@ -93,16 +97,15 @@ class _RegisiterVistorTemplateComponentWidgetState
return false; return false;
} }
// if (_isVisitorRegistered) { if (_isVisitorRegistered) {
// return false; return false;
// } }
return true; return true;
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
BehaviorSubject<bool> visitorAlreadyRegistered = BehaviorSubject<bool>();
context.watch<FFAppState>(); context.watch<FFAppState>();
return Align( return Align(
alignment: const AlignmentDirectional(0.0, 1.0), alignment: const AlignmentDirectional(0.0, 1.0),
@ -226,71 +229,61 @@ class _RegisiterVistorTemplateComponentWidgetState
useGoogleFonts: GoogleFonts.asMap().containsKey( useGoogleFonts: GoogleFonts.asMap().containsKey(
FlutterFlowTheme.of(context).bodyMediumFamily), FlutterFlowTheme.of(context).bodyMediumFamily),
), ),
onChanged: (value) {
_model.debounce(() async {
log('data');
var data = await _model.getVisitanteByDocument(
value, context);
log('data: $data');
setState(() {
_isVisitorRegistered = data;
});
}, const Duration(milliseconds: 500));
},
validator: validator:
_model.textController2Validator.asValidator(context), _model.textController2Validator.asValidator(context),
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.allow(RegExp('[0-9]')), FilteringTextInputFormatter.allow(RegExp('[0-9]')),
], ],
), ),
FutureBuilder( _model.textController2.text.isEmpty
future: _model.textController2.text.isNotEmpty ? const SizedBox()
? _model.getVisitanteByDocument( : _isVisitorRegistered == true
_model.textController2.text, context) ? Row(
: null, mainAxisSize: MainAxisSize.max,
builder: (BuildContext context, AsyncSnapshot snapshot) { mainAxisAlignment: MainAxisAlignment.start,
if (snapshot.connectionState == children: [
ConnectionState.waiting) { Padding(
return const SizedBox(); padding: const EdgeInsetsDirectional.only(
} else if (snapshot.hasError || top: 5, start: 12),
snapshot.data == null || child: Text(
snapshot.data == '') { FFLocalizations.of(context)
// safeSetState(() => _isVisitorRegistered = false); .getVariableText(
_isVisitorRegistered = false; enText: 'Visitor already registered',
visitorAlreadyRegistered.add(true); ptText: 'Visitante já cadastrado',
return const SizedBox(); ),
} else { style: FlutterFlowTheme.of(context)
_isVisitorRegistered = true; .labelSmall
visitorAlreadyRegistered.add(false); .override(
return _model.textController2.text.isEmpty fontFamily: 'Nunito',
? const SizedBox() color: Theme.of(context)
: Row( .brightness ==
mainAxisSize: MainAxisSize.max, Brightness.dark
mainAxisAlignment: MainAxisAlignment.start, ? Color.alphaBlend(
children: [ Colors.white
Padding( .withOpacity(0.7),
padding: const EdgeInsetsDirectional.only( Colors.red)
top: 5, start: 12), : Color.alphaBlend(
child: Text( Colors.black
FFLocalizations.of(context) .withOpacity(0.25),
.getVariableText( Colors.red),
enText: fontSize: 13.0,
'Visitor already registered', letterSpacing: 0.0,
ptText: 'Visitante já cadastrado', )),
), ),
style: FlutterFlowTheme.of(context) ],
.labelSmall )
.override( : const SizedBox()
fontFamily: 'Nunito',
color: Theme.of(context)
.brightness ==
Brightness.dark
? Color.alphaBlend(
Colors.white
.withOpacity(0.7),
Colors.red)
: Color.alphaBlend(
Colors.black
.withOpacity(0.25),
Colors.red),
fontSize: 13.0,
letterSpacing: 0.0,
)),
),
],
);
}
},
),
]), ]),
), ),
Padding( Padding(
@ -805,111 +798,110 @@ class _RegisiterVistorTemplateComponentWidgetState
child: FFButtonWidget( child: FFButtonWidget(
onPressed: _isFormValid(context) onPressed: _isFormValid(context)
? () async { ? () async {
if (visitorAlreadyRegistered.value == true) { _model.imgBase64 =
_model.imgBase64 = await actions.convertImageFileToBase64(
await actions.convertImageFileToBase64( _model.uploadedLocalFile,
_model.uploadedLocalFile, );
); _model.scheduleVisitor =
_model.scheduleVisitor = await PhpGroup.postScheduleVisitorCall
await PhpGroup.postScheduleVisitorCall .call(
.call( devUUID: FFAppState().devUUID,
devUUID: FFAppState().devUUID, userUUID: FFAppState().userUUID,
userUUID: FFAppState().userUUID, cliID: FFAppState().cliUUID,
cliID: FFAppState().cliUUID, atividade: 'putVisitante',
atividade: 'putVisitante', documento: _model.textController2.text,
documento: _model.textController2.text, nome: _model.textController1.text,
nome: _model.textController1.text, tipo: _model.dropDownValue ==
tipo: _model.dropDownValue == FFLocalizations.of(context).getText(
FFLocalizations.of(context).getText( 'n8vddmcq' /* Visitante */,
'n8vddmcq' /* Visitante */, )
) ? 'V'
? 'V' : 'P',
: 'P', foto: 'base64;jpeg,${_model.imgBase64}',
foto: 'base64;jpeg,${_model.imgBase64}', )
) .onError((e, s) async {
.onError((e, s) async { return await showAdaptiveDialog(
return await showAdaptiveDialog( context: context,
context: context, builder: (context) {
builder: (context) { return GestureDetector(
return GestureDetector( onTap: () => Navigator.pop(context),
onTap: () => Navigator.pop(context), child: Padding(
child: Padding( padding: MediaQuery.viewInsetsOf(context),
padding: child: Dialog(
MediaQuery.viewInsetsOf(context), backgroundColor: Colors.transparent,
child: Dialog( child: ThrowExceptionWidget(
backgroundColor: Colors.transparent, msg: FFLocalizations.of(context)
child: ThrowExceptionWidget( .getVariableText(
msg: FFLocalizations.of(context) ptText:
.getVariableText( 'Você esqueceu de adicionar algum dado obrigatório. Verifique se a imagem, nome, tipo e documento foram preenchidos corretamente.',
ptText: enText:
'Você esqueceu de adicionar algum dado obrigatório. Verifique se a imagem, nome, tipo e documento foram preenchidos corretamente.', 'You forgot to add some required data. Check if the image, name, type and document were filled in correctly.',
enText:
'You forgot to add some required data. Check if the image, name, type and document were filled in correctly.',
),
), ),
), ),
), ),
);
},
);
});
if (PhpGroup.postScheduleVisitorCall.error(
(_model.scheduleVisitor?.jsonBody ?? ''),
) ==
false) {
setState(() {
_model.textController1?.clear();
_model.textController2?.clear();
_model.textController3?.clear();
_model.textController4?.clear();
_model.dropDownValueController?.reset();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
FFLocalizations.of(context).getVariableText(
ptText:
'Visitante cadastrado com sucesso.',
enText:
'Visitor successfully registered.'),
style: TextStyle(
color:
FlutterFlowTheme.of(context)
.info)),
backgroundColor:
FlutterFlowTheme.of(context).primary,
duration: const Duration(seconds: 3),
width: MediaQuery.of(context).size.width,
behavior: SnackBarBehavior.floating,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),
),
),
), ),
); );
if (widget.source == },
'VisitorNotFoundComponent') { );
Navigator.pop(context); });
} if (PhpGroup.postScheduleVisitorCall.error(
}); (_model.scheduleVisitor?.jsonBody ?? ''),
} else { ) ==
return DialogUtil.error( false) {
context, setState(() {
PhpGroup.postScheduleVisitorCall _model.textController1?.clear();
.errorMsg( _model.textController2?.clear();
_model.scheduleVisitor?.jsonBody) _model.textController3?.clear();
.toString()); _model.textController4?.clear();
} _model.dropDownValueController?.reset();
_model.uploadedLocalFile = FFUploadedFile(
bytes: Uint8List.fromList([]));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
FFLocalizations.of(context).getVariableText(
ptText:
'Visitante cadastrado com sucesso.',
enText:
'Visitor successfully registered.'),
style: TextStyle(
color: FlutterFlowTheme.of(context)
.info)),
backgroundColor:
FlutterFlowTheme.of(context).primary,
duration: const Duration(seconds: 3),
width: MediaQuery.of(context).size.width,
behavior: SnackBarBehavior.floating,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),
),
),
),
);
if (widget.source ==
'VisitorNotFoundComponent') {
Navigator.pop(context);
}
});
} else { } else {
DialogUtil.error( return DialogUtil.error(
context, context,
FFLocalizations.of(context).getVariableText( PhpGroup.postScheduleVisitorCall.errorMsg(
ptText: _model
'Visitante já cadastrado. Verifique se o documento foi preenchido corretamente.', .scheduleVisitor?.jsonBody) ==
enText: null
'Visitor already registered. Check if the document was filled in correctly.', ? FFLocalizations.of(context)
)); .getVariableText(
ptText:
'Erro ao se conectar com o servidor',
enText: 'Error connecting to server',
)
: PhpGroup.postScheduleVisitorCall
.errorMsg(
_model.scheduleVisitor?.jsonBody)
.toString());
} }
} }
: null, : null,

View File

@ -13,11 +13,11 @@ import 'package:intl/intl.dart';
class ScheduleCompleteVisitPageModel class ScheduleCompleteVisitPageModel
extends FlutterFlowModel<ScheduleCompleteVisitPageWidget> { extends FlutterFlowModel<ScheduleCompleteVisitPageWidget> {
final _visitHistoryManager = StreamRequestManager<ApiCallResponse>(); final _visitHistoryManager = FutureRequestManager<ApiCallResponse>();
Stream<ApiCallResponse> visitHistory({ Future<ApiCallResponse> visitHistory({
String? uniqueQueryKey, String? uniqueQueryKey,
bool? overrideCache, bool? overrideCache,
required Stream<ApiCallResponse> Function() requestFn, required Future<ApiCallResponse> Function() requestFn,
}) => }) =>
_visitHistoryManager.performRequest( _visitHistoryManager.performRequest(
uniqueQueryKey: uniqueQueryKey, uniqueQueryKey: uniqueQueryKey,

View File

@ -10,6 +10,7 @@ import 'package:hub/actions/actions.dart';
import 'package:hub/backend/api_requests/api_calls.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/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/components/templates_components/details_component/details_component_action.dart';
import 'package:hub/components/templates_components/details_component/details_component_widget.dart';
import 'package:hub/components/templates_components/visit_details_modal_template_component/visit_details_modal_template_component_widget.dart'; import 'package:hub/components/templates_components/visit_details_modal_template_component/visit_details_modal_template_component_widget.dart';
import 'package:hub/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart'; import 'package:hub/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart';
import 'package:hub/flutter_flow/custom_functions.dart'; import 'package:hub/flutter_flow/custom_functions.dart';
@ -1580,18 +1581,25 @@ Widget scheduleVisit(
child: SizedBox( child: SizedBox(
// width: MediaQuery.of(context).size.width, // width: MediaQuery.of(context).size.width,
// height: MediaQuery.of(context).size.height * 0.7, // height: MediaQuery.of(context).size.height * 0.7,
child: VisitDetailsModalTemplateComponentWidget( // child: VisitDetailsModalTemplateComponentWidget(
visitStartDateStr: _model.textController1.text, // visitStartDateStr: _model.textController1.text,
visitEndDateStr: _model.textController2.text, // visitEndDateStr: _model.textController2.text,
visitReasonStr: _model.dropDownValue1, // visitReasonStr: _model.dropDownValue1,
visitLevelStr: _model.dropDownValue2, // visitLevelStr: _model.dropDownValue2,
visitTempStr: // visitTempStr:
_model.switchValue == true ? 'Sim' : 'Não', // _model.switchValue == true ? 'Sim' : 'Não',
visitObsStr: _model.textController3.text, // visitObsStr: _model.textController3.text,
visitorStrList: _model.visitorStrList, // visitorStrList: _model.visitorStrList,
visitorJsonList: _model.visitorJsonList, // visitorJsonList: _model.visitorJsonList,
updateToggleIdx: () async {}, // updateToggleIdx: () async {},
repeatVisitSchedule: () async {}, // repeatVisitSchedule: () async {},
// ),
child: VisitRequestTemplateComponentWidget(
buttons: [],
imageHashMap: {},
labelsHashMap: {},
statusHashMap: [],
onTapCardItemAction: () async {},
), ),
), ),
), ),

View File

@ -11,7 +11,6 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart';
import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/internationalization.dart';
import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart';
import 'package:provider/provider.dart';
class VisitHistoryWidget extends StatefulWidget { class VisitHistoryWidget extends StatefulWidget {
VisitHistoryWidget({ VisitHistoryWidget({
@ -23,153 +22,153 @@ class VisitHistoryWidget extends StatefulWidget {
} }
class _VisitHistoryWidgetState extends State<VisitHistoryWidget> { class _VisitHistoryWidgetState extends State<VisitHistoryWidget> {
late Future<ApiCallResponse> visitFuture;
var pageNumber = 1;
@override @override
Widget build(BuildContext context) { void initState() {
var response = ScheduleCompleteVisitPageModel().visitHistory( super.initState();
// Inicialização inicial
visitFuture = ScheduleCompleteVisitPageModel().visitHistory(
requestFn: () => PhpGroup.getVisitsCall.call( requestFn: () => PhpGroup.getVisitsCall.call(
devUUID: FFAppState().devUUID, devUUID: FFAppState().devUUID,
userUUID: FFAppState().userUUID, userUUID: FFAppState().userUUID,
cliID: FFAppState().cliUUID, cliID: FFAppState().cliUUID,
atividade: 'getVisitas', atividade: 'getVisitas',
pageSize: 100, pageSize: 100,
pageNumber: 1, pageNumber: pageNumber,
),
);
return Container(
width: double.infinity,
height: 900.0,
decoration: BoxDecoration(
color: FlutterFlowTheme.of(context).primaryBackground,
),
// child: Consumer<ScheduleCompleteVisitPageModel>(
child: StreamBuilder<dynamic>(
stream: response,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
FlutterFlowTheme.of(context).primary,
),
),
);
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else if (!snapshot.hasData || snapshot.data!.jsonBody == null) {
return const Center(child: Text('No visits found'));
}
var wrapGetVisitsResponse = snapshot.data!;
var visitaWrap = PhpGroup.getVisitsCall
.visitasList(wrapGetVisitsResponse.jsonBody)
?.toList() ??
[];
return ListView.builder(
itemCount: visitaWrap.length,
shrinkWrap: true,
physics: const BouncingScrollPhysics(),
itemBuilder: (context, index) {
final visitaWrapItem = visitaWrap[index];
return CardItemTemplateComponentWidget(
imageHashMap: {
'key': visitaWrapItem['VTE_DOCUMENTO'] ?? '',
'value': 'E',
},
labelsHashMap: {
'Nome:': visitaWrapItem['VTE_NOME'] ?? '',
'Inicio:': visitaWrapItem['VAW_DTINICIO'] ?? '',
'Fim:': visitaWrapItem['VAW_DTFIM'] ?? '',
},
statusHashMap: [
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.active)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Ativo',
enText: 'Active',
): FlutterFlowTheme.of(context).warning,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) ==
status.finished)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Finalizado',
enText: 'Finished',
): FlutterFlowTheme.of(context).success,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.unknown)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Desconhecido',
enText: 'Unknown',
): FlutterFlowTheme.of(context).alternate,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) ==
status.canceled)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Cancelado',
enText: 'Canceled',
): FlutterFlowTheme.of(context).error,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.blocked)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Bloqueado',
enText: 'Blocked',
): FlutterFlowTheme.of(context).error,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) ==
status.inactive)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Inactive',
enText: 'Inactive',
): FlutterFlowTheme.of(context).error,
},
],
onTapCardItemAction: () async {
await showDialog(
// isScrollControlled: true,
// isDismissible: true,
// backgroundColor: Colors.transparent,
useSafeArea: true,
context: context,
builder: (context) {
return Dialog(
alignment: Alignment.center,
child: buildDetails(
visitaWrapItem,
context,
changeStatusAction,
),
);
},
).whenComplete(() async {
final newResponseStream =
ScheduleCompleteVisitPageModel().visitHistory(
requestFn: () => PhpGroup.getVisitsCall.call(
devUUID: FFAppState().devUUID,
userUUID: FFAppState().userUUID,
cliID: FFAppState().cliUUID,
atividade: 'getVisitas',
pageSize: 100,
pageNumber: 1,
),
);
newResponseStream.listen((newResponse) {
if (mounted) {
safeSetState(() {
response = newResponse.jsonBody;
});
} else {}
}).onError((err) {});
}).catchError((err, stack) {});
},
);
},
);
},
), ),
); );
} }
void updateVisitFuture() {
// Atualização do valor da variável late
setState(() {
visitFuture = ScheduleCompleteVisitPageModel().visitHistory(
requestFn: () => PhpGroup.getVisitsCall.call(
devUUID: FFAppState().devUUID,
userUUID: FFAppState().userUUID,
cliID: FFAppState().cliUUID,
atividade: 'getVisitas',
pageSize: 100,
pageNumber: pageNumber,
),
);
});
}
@override
Widget build(BuildContext context) {
return FutureBuilder<dynamic>(
future: visitFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
FlutterFlowTheme.of(context).primary,
),
),
);
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else if (!snapshot.hasData || snapshot.data!.jsonBody == null) {
return Center(
child: Text(FFLocalizations.of(context).getVariableText(
ptText: 'Nenhum visitante foi encontrado',
enText: 'No visitors found',
)));
}
var wrapGetVisitsResponse = snapshot.data!;
var visitaWrap = PhpGroup.getVisitsCall
.visitasList(wrapGetVisitsResponse.jsonBody)
?.toList() ??
[];
return ListView.builder(
itemCount: visitaWrap.length,
shrinkWrap: true,
physics: const BouncingScrollPhysics(),
itemBuilder: (context, index) {
final visitaWrapItem = visitaWrap[index];
return CardItemTemplateComponentWidget(
imageHashMap: {
'key': visitaWrapItem['VTE_DOCUMENTO'] ?? '',
'value': 'E',
},
labelsHashMap: {
'Nome:': visitaWrapItem['VTE_NOME'] ?? '',
'Inicio:': visitaWrapItem['VAW_DTINICIO'] ?? '',
'Fim:': visitaWrapItem['VAW_DTFIM'] ?? '',
},
statusHashMap: [
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.active)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Ativo',
enText: 'Active',
): FlutterFlowTheme.of(context).warning,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.finished)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Finalizado',
enText: 'Finished',
): FlutterFlowTheme.of(context).success,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.unknown)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Desconhecido',
enText: 'Unknown',
): FlutterFlowTheme.of(context).alternate,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.canceled)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Cancelado',
enText: 'Canceled',
): FlutterFlowTheme.of(context).error,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.blocked)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Bloqueado',
enText: 'Blocked',
): FlutterFlowTheme.of(context).error,
},
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.inactive)
{
FFLocalizations.of(context).getVariableText(
ptText: 'Inativo',
enText: 'Inactive',
): FlutterFlowTheme.of(context).error,
},
],
onTapCardItemAction: () async {
await showDialog(
useSafeArea: true,
context: context,
builder: (context) {
return Dialog(
alignment: Alignment.center,
child: buildDetails(
visitaWrapItem,
context,
changeStatusAction,
),
);
},
).whenComplete(() {
log('Dialog closed');
updateVisitFuture();
}).catchError((err, stack) {});
},
);
},
);
},
);
}
} }