fix visitorRegister and visitHIstory
This commit is contained in:
parent
016be1df54
commit
bc1c684d72
|
@ -1417,21 +1417,17 @@ class PostProvVisitSchedulingCall {
|
|||
}
|
||||
|
||||
class GetVisitsCall {
|
||||
Stream<ApiCallResponse> call({
|
||||
Future<ApiCallResponse> call({
|
||||
String? devUUID = '',
|
||||
String? userUUID = '',
|
||||
String? cliID = '',
|
||||
String? atividade = '',
|
||||
int? pageSize,
|
||||
int? pageNumber,
|
||||
}) {
|
||||
}) async {
|
||||
final baseUrl = PhpGroup.getBaseUrl();
|
||||
final StreamController<ApiCallResponse> controller = StreamController();
|
||||
|
||||
Future.microtask(
|
||||
() async {
|
||||
try {
|
||||
final response = await ApiManager.instance.makeApiCall(
|
||||
return ApiManager.instance.makeApiCall(
|
||||
callName: 'getVisits',
|
||||
apiUrl: '$baseUrl/processRequest.php',
|
||||
callType: ApiCallType.POST,
|
||||
|
@ -1454,16 +1450,6 @@ class GetVisitsCall {
|
|||
isStreamingApi: false,
|
||||
alwaysAllowBody: false,
|
||||
);
|
||||
controller.add(response);
|
||||
controller.close();
|
||||
} catch (e) {
|
||||
controller.addError(e);
|
||||
controller.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
bool? error(dynamic response) => castToType<bool>(getJsonField(
|
||||
|
|
|
@ -44,7 +44,7 @@ Widget buildDetails(
|
|||
visitaWrapItem['VTE_DOCUMENTO'] ?? '',
|
||||
)
|
||||
.then((value) {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context, value);
|
||||
if (value == false) {
|
||||
showSnackbar(
|
||||
context,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
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
|
||||
extends FlutterFlowModel<RegisiterVistorTemplateComponentWidget> {
|
||||
/// State fields for stateful widgets in this page.
|
||||
Timer? _debounceTimer;
|
||||
|
||||
final unfocusNode = FocusNode();
|
||||
bool isDataUploading = false;
|
||||
FFUploadedFile uploadedLocalFile =
|
||||
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.
|
||||
FocusNode? textFieldFocusNode1;
|
||||
TextEditingController? textController1;
|
||||
|
@ -35,7 +44,7 @@ class RegisiterVistorTemplateComponentModel
|
|||
return null;
|
||||
}
|
||||
|
||||
Future<bool?> getVisitanteByDocument(
|
||||
Future<bool> getVisitanteByDocument(
|
||||
String document, BuildContext context) async {
|
||||
final response = await PhpGroup.getVisitorByDocCall.call(
|
||||
devUUID: FFAppState().devUUID,
|
||||
|
@ -49,7 +58,7 @@ class RegisiterVistorTemplateComponentModel
|
|||
response.jsonBody['error'] != 'false') {
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// State field(s) for TextField widget.
|
||||
|
|
|
@ -39,10 +39,14 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
bool _isVisitorRegistered = false;
|
||||
BehaviorSubject<bool> visitorAlreadyRegistered = BehaviorSubject<bool>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
visitorAlreadyRegistered = BehaviorSubject<bool>.seeded(false);
|
||||
|
||||
_model =
|
||||
createModel(context, () => RegisiterVistorTemplateComponentModel());
|
||||
|
||||
|
@ -93,16 +97,15 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
return false;
|
||||
}
|
||||
|
||||
// if (_isVisitorRegistered) {
|
||||
// return false;
|
||||
// }
|
||||
if (_isVisitorRegistered) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
BehaviorSubject<bool> visitorAlreadyRegistered = BehaviorSubject<bool>();
|
||||
context.watch<FFAppState>();
|
||||
return Align(
|
||||
alignment: const AlignmentDirectional(0.0, 1.0),
|
||||
|
@ -226,34 +229,27 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
useGoogleFonts: GoogleFonts.asMap().containsKey(
|
||||
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:
|
||||
_model.textController2Validator.asValidator(context),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp('[0-9]')),
|
||||
],
|
||||
),
|
||||
FutureBuilder(
|
||||
future: _model.textController2.text.isNotEmpty
|
||||
? _model.getVisitanteByDocument(
|
||||
_model.textController2.text, context)
|
||||
: null,
|
||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||
if (snapshot.connectionState ==
|
||||
ConnectionState.waiting) {
|
||||
return const SizedBox();
|
||||
} else if (snapshot.hasError ||
|
||||
snapshot.data == null ||
|
||||
snapshot.data == '') {
|
||||
// safeSetState(() => _isVisitorRegistered = false);
|
||||
_isVisitorRegistered = false;
|
||||
visitorAlreadyRegistered.add(true);
|
||||
return const SizedBox();
|
||||
} else {
|
||||
_isVisitorRegistered = true;
|
||||
visitorAlreadyRegistered.add(false);
|
||||
return _model.textController2.text.isEmpty
|
||||
_model.textController2.text.isEmpty
|
||||
? const SizedBox()
|
||||
: Row(
|
||||
: _isVisitorRegistered == true
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
|
@ -263,8 +259,7 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
child: Text(
|
||||
FFLocalizations.of(context)
|
||||
.getVariableText(
|
||||
enText:
|
||||
'Visitor already registered',
|
||||
enText: 'Visitor already registered',
|
||||
ptText: 'Visitante já cadastrado',
|
||||
),
|
||||
style: FlutterFlowTheme.of(context)
|
||||
|
@ -287,10 +282,8 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
: const SizedBox()
|
||||
]),
|
||||
),
|
||||
Padding(
|
||||
|
@ -805,7 +798,6 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
child: FFButtonWidget(
|
||||
onPressed: _isFormValid(context)
|
||||
? () async {
|
||||
if (visitorAlreadyRegistered.value == true) {
|
||||
_model.imgBase64 =
|
||||
await actions.convertImageFileToBase64(
|
||||
_model.uploadedLocalFile,
|
||||
|
@ -834,8 +826,7 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
return GestureDetector(
|
||||
onTap: () => Navigator.pop(context),
|
||||
child: Padding(
|
||||
padding:
|
||||
MediaQuery.viewInsetsOf(context),
|
||||
padding: MediaQuery.viewInsetsOf(context),
|
||||
child: Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
child: ThrowExceptionWidget(
|
||||
|
@ -863,6 +854,8 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
_model.textController3?.clear();
|
||||
_model.textController4?.clear();
|
||||
_model.dropDownValueController?.reset();
|
||||
_model.uploadedLocalFile = FFUploadedFile(
|
||||
bytes: Uint8List.fromList([]));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
|
@ -872,8 +865,7 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
enText:
|
||||
'Visitor successfully registered.'),
|
||||
style: TextStyle(
|
||||
color:
|
||||
FlutterFlowTheme.of(context)
|
||||
color: FlutterFlowTheme.of(context)
|
||||
.info)),
|
||||
backgroundColor:
|
||||
FlutterFlowTheme.of(context).primary,
|
||||
|
@ -896,21 +888,21 @@ class _RegisiterVistorTemplateComponentWidgetState
|
|||
} else {
|
||||
return DialogUtil.error(
|
||||
context,
|
||||
PhpGroup.postScheduleVisitorCall
|
||||
PhpGroup.postScheduleVisitorCall.errorMsg(
|
||||
_model
|
||||
.scheduleVisitor?.jsonBody) ==
|
||||
null
|
||||
? FFLocalizations.of(context)
|
||||
.getVariableText(
|
||||
ptText:
|
||||
'Erro ao se conectar com o servidor',
|
||||
enText: 'Error connecting to server',
|
||||
)
|
||||
: PhpGroup.postScheduleVisitorCall
|
||||
.errorMsg(
|
||||
_model.scheduleVisitor?.jsonBody)
|
||||
.toString());
|
||||
}
|
||||
} else {
|
||||
DialogUtil.error(
|
||||
context,
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText:
|
||||
'Visitante já cadastrado. Verifique se o documento foi preenchido corretamente.',
|
||||
enText:
|
||||
'Visitor already registered. Check if the document was filled in correctly.',
|
||||
));
|
||||
}
|
||||
}
|
||||
: null,
|
||||
text: FFLocalizations.of(context).getText(
|
||||
|
|
|
@ -13,11 +13,11 @@ import 'package:intl/intl.dart';
|
|||
|
||||
class ScheduleCompleteVisitPageModel
|
||||
extends FlutterFlowModel<ScheduleCompleteVisitPageWidget> {
|
||||
final _visitHistoryManager = StreamRequestManager<ApiCallResponse>();
|
||||
Stream<ApiCallResponse> visitHistory({
|
||||
final _visitHistoryManager = FutureRequestManager<ApiCallResponse>();
|
||||
Future<ApiCallResponse> visitHistory({
|
||||
String? uniqueQueryKey,
|
||||
bool? overrideCache,
|
||||
required Stream<ApiCallResponse> Function() requestFn,
|
||||
required Future<ApiCallResponse> Function() requestFn,
|
||||
}) =>
|
||||
_visitHistoryManager.performRequest(
|
||||
uniqueQueryKey: uniqueQueryKey,
|
||||
|
|
|
@ -10,6 +10,7 @@ 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/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/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart';
|
||||
import 'package:hub/flutter_flow/custom_functions.dart';
|
||||
|
@ -1580,18 +1581,25 @@ Widget scheduleVisit(
|
|||
child: SizedBox(
|
||||
// width: MediaQuery.of(context).size.width,
|
||||
// height: MediaQuery.of(context).size.height * 0.7,
|
||||
child: VisitDetailsModalTemplateComponentWidget(
|
||||
visitStartDateStr: _model.textController1.text,
|
||||
visitEndDateStr: _model.textController2.text,
|
||||
visitReasonStr: _model.dropDownValue1,
|
||||
visitLevelStr: _model.dropDownValue2,
|
||||
visitTempStr:
|
||||
_model.switchValue == true ? 'Sim' : 'Não',
|
||||
visitObsStr: _model.textController3.text,
|
||||
visitorStrList: _model.visitorStrList,
|
||||
visitorJsonList: _model.visitorJsonList,
|
||||
updateToggleIdx: () async {},
|
||||
repeatVisitSchedule: () async {},
|
||||
// child: VisitDetailsModalTemplateComponentWidget(
|
||||
// visitStartDateStr: _model.textController1.text,
|
||||
// visitEndDateStr: _model.textController2.text,
|
||||
// visitReasonStr: _model.dropDownValue1,
|
||||
// visitLevelStr: _model.dropDownValue2,
|
||||
// visitTempStr:
|
||||
// _model.switchValue == true ? 'Sim' : 'Não',
|
||||
// visitObsStr: _model.textController3.text,
|
||||
// visitorStrList: _model.visitorStrList,
|
||||
// visitorJsonList: _model.visitorJsonList,
|
||||
// updateToggleIdx: () async {},
|
||||
// repeatVisitSchedule: () async {},
|
||||
// ),
|
||||
child: VisitRequestTemplateComponentWidget(
|
||||
buttons: [],
|
||||
imageHashMap: {},
|
||||
labelsHashMap: {},
|
||||
statusHashMap: [],
|
||||
onTapCardItemAction: () async {},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -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/internationalization.dart';
|
||||
import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class VisitHistoryWidget extends StatefulWidget {
|
||||
VisitHistoryWidget({
|
||||
|
@ -23,27 +22,45 @@ class VisitHistoryWidget extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _VisitHistoryWidgetState extends State<VisitHistoryWidget> {
|
||||
late Future<ApiCallResponse> visitFuture;
|
||||
var pageNumber = 1;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var response = ScheduleCompleteVisitPageModel().visitHistory(
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Inicialização inicial
|
||||
visitFuture = ScheduleCompleteVisitPageModel().visitHistory(
|
||||
requestFn: () => PhpGroup.getVisitsCall.call(
|
||||
devUUID: FFAppState().devUUID,
|
||||
userUUID: FFAppState().userUUID,
|
||||
cliID: FFAppState().cliUUID,
|
||||
atividade: 'getVisitas',
|
||||
pageSize: 100,
|
||||
pageNumber: 1,
|
||||
pageNumber: pageNumber,
|
||||
),
|
||||
);
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: 900.0,
|
||||
decoration: BoxDecoration(
|
||||
color: FlutterFlowTheme.of(context).primaryBackground,
|
||||
}
|
||||
|
||||
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,
|
||||
),
|
||||
// child: Consumer<ScheduleCompleteVisitPageModel>(
|
||||
child: StreamBuilder<dynamic>(
|
||||
stream: response,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<dynamic>(
|
||||
future: visitFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return Center(
|
||||
|
@ -56,13 +73,19 @@ class _VisitHistoryWidgetState extends State<VisitHistoryWidget> {
|
|||
} 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'));
|
||||
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,
|
||||
|
@ -87,8 +110,7 @@ class _VisitHistoryWidgetState extends State<VisitHistoryWidget> {
|
|||
enText: 'Active',
|
||||
): FlutterFlowTheme.of(context).warning,
|
||||
},
|
||||
if (getStatus(visitaWrapItem['VAW_STATUS']) ==
|
||||
status.finished)
|
||||
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.finished)
|
||||
{
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Finalizado',
|
||||
|
@ -102,8 +124,7 @@ class _VisitHistoryWidgetState extends State<VisitHistoryWidget> {
|
|||
enText: 'Unknown',
|
||||
): FlutterFlowTheme.of(context).alternate,
|
||||
},
|
||||
if (getStatus(visitaWrapItem['VAW_STATUS']) ==
|
||||
status.canceled)
|
||||
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.canceled)
|
||||
{
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Cancelado',
|
||||
|
@ -117,23 +138,18 @@ class _VisitHistoryWidgetState extends State<VisitHistoryWidget> {
|
|||
enText: 'Blocked',
|
||||
): FlutterFlowTheme.of(context).error,
|
||||
},
|
||||
if (getStatus(visitaWrapItem['VAW_STATUS']) ==
|
||||
status.inactive)
|
||||
if (getStatus(visitaWrapItem['VAW_STATUS']) == status.inactive)
|
||||
{
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Inactive',
|
||||
ptText: 'Inativo',
|
||||
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,
|
||||
|
@ -144,32 +160,15 @@ class _VisitHistoryWidgetState extends State<VisitHistoryWidget> {
|
|||
),
|
||||
);
|
||||
},
|
||||
).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) {});
|
||||
).whenComplete(() {
|
||||
log('Dialog closed');
|
||||
updateVisitFuture();
|
||||
}).catchError((err, stack) {});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue