diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart index 6e812792..3e518237 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart @@ -37,6 +37,7 @@ class RegisiterVistorTemplateComponentModel Future getVisitanteByDocument( String document, BuildContext context) async { + final response = await PhpGroup.getVisitorByDocCall.call( devUUID: FFAppState().devUUID, userUUID: FFAppState().userUUID, @@ -44,6 +45,7 @@ class RegisiterVistorTemplateComponentModel atividade: 'getVisitante', documento: document, ); + log('${response.jsonBody}'); if (response.jsonBody['visitante']['VTE_ID'] != '0' && response.jsonBody['error'] != 'false') { diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart index 1ab51600..e18779eb 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart @@ -38,6 +38,8 @@ class _RegisiterVistorTemplateComponentWidgetState final scaffoldKey = GlobalKey(); + bool _isVisitorRegistered = false; + @override void initState() { super.initState(); @@ -71,6 +73,32 @@ class _RegisiterVistorTemplateComponentWidgetState setState(() {}); } + bool _isFormValid(BuildContext context) { + + if (_model.uploadedLocalFile.bytes?.isEmpty ?? true) { + return false; + } + + if (_model.textController1.text.isEmpty || _model.textController1.text == '') { + return false; + } + + if (_model.dropDownValue == null || _model.dropDownValue!.isEmpty || _model.dropDownValue == '') { + return false; + } + + if (_model.textController2.text.isEmpty || _model.textController2.text == '') { + return false; + } + + log("Visitante Já Cadastrado $_isVisitorRegistered"); + if (_isVisitorRegistered) { + return false; + } + + return true; + } + @override Widget build(BuildContext context) { BehaviorSubject visitorAlreadyRegistered = BehaviorSubject(); @@ -216,9 +244,11 @@ class _RegisiterVistorTemplateComponentWidgetState } else if (snapshot.hasError || snapshot.data == null || snapshot.data == '') { + _isVisitorRegistered = false; visitorAlreadyRegistered.add(true); return const SizedBox(); } else { + _isVisitorRegistered = true; visitorAlreadyRegistered.add(false); return _model.textController2.text.isEmpty ? const SizedBox() @@ -775,12 +805,7 @@ class _RegisiterVistorTemplateComponentWidgetState padding: const EdgeInsetsDirectional.fromSTEB(0.0, 65.0, 0.0, 0.0), child: FFButtonWidget( - onPressed: (((_model.uploadedLocalFile.bytes?.isNotEmpty ?? - false)) && - (_model.textController1.text != '') && - (_model.dropDownValue != null && - _model.dropDownValue != '') && - (_model.textController2.text != '')) + onPressed: _isFormValid(context) ? () async { log(visitorAlreadyRegistered.value.toString()); if (visitorAlreadyRegistered.value == true) {