Refactor autofocus behavior in opt_modal_widget.dart and update visit date in nav.dart

This commit is contained in:
jantunesmesias 2024-07-12 13:01:03 -03:00
parent 20c8d9ab8f
commit 511910bb39
12 changed files with 236 additions and 74 deletions

View File

@ -1,3 +1,5 @@
import 'package:f_r_e_hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart';
import 'package:f_r_e_hub/pages/home_page/home_page_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '/actions/actions.dart' as action_blocks; import '/actions/actions.dart' as action_blocks;
@ -6,6 +8,8 @@ import '/components/molecular_components/throw_exception/throw_exception_widget.
import '/custom_code/actions/index.dart' as actions; import '/custom_code/actions/index.dart' as actions;
import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart'; import '/flutter_flow/flutter_flow_util.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/flutter_flow/random_data_util.dart' as random_data; import '/flutter_flow/random_data_util.dart' as random_data;
Future repeatVisitScheduleAction( Future repeatVisitScheduleAction(
@ -387,6 +391,58 @@ Future<void> snackbar(BuildContext context, {required bool opt}) async {
); );
} }
Future<bool> checkLocals({
String? cliUUID,
required BuildContext context,
required HomePageModel model,
required void Function(void Function()) safeSetState,
}) async {
// A chamada para a API permanece a mesma, assumindo que é necessária sempre.
final response = await PhpGroup.getLocalsCall.call(
devUUID: FFAppState().devUUID,
userUUID: FFAppState().userUUID,
);
// Verificação rápida de erro para evitar processamento desnecessário.
if (response.jsonBody['error']) {
debugPrint("checkLocals => Erro encontrado na resposta");
return false;
}
// Uso eficiente de coleções para verificar a condição desejada.
final String uuid = cliUUID ?? FFAppState().cliUUID;
final bool itemFound = response.jsonBody['locais'].any(
(local) => local['CLI_ID'] == uuid && local['CLU_STATUS'] == "A",
);
// Log e retorno condicional baseado no resultado da busca.
if (itemFound) {
debugPrint("checkLocals => Item encontrado com CLI_ID $uuid e CLU_STATUS A");
return true;
} else {
debugPrint("checkLocals => Item não encontrado com CLI_ID $uuid e CLU_STATUS A");
// A chamada para showModalBottomSheet permanece, mas a atualização da UI é otimizada.
await showModalBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
enableDrag: false,
context: context,
builder: (context) => GestureDetector(
onTap: () => model.unfocusNode.canRequestFocus
? FocusScope.of(context).requestFocus(model.unfocusNode)
: FocusScope.of(context).unfocus(),
child: Padding(
padding: MediaQuery.viewInsetsOf(context),
child: const BottomArrowLinkedLocalsComponentWidget(),
),
),
);
safeSetState(() {}); // Chamada otimizada fora do then para evitar encadeamentos desnecessários.
return false;
}
}
Future changeStatusAction( Future changeStatusAction(
BuildContext context, BuildContext context,
String status, String status,
@ -436,4 +492,6 @@ Future changeStatusAction(
default: default:
break; break;
} }
} }

View File

@ -222,7 +222,7 @@ class _OptModalWidgetState extends State<OptModalWidget> {
child: TextFormField( child: TextFormField(
controller: _model.textController, controller: _model.textController,
focusNode: _model.textFieldFocusNode, focusNode: _model.textFieldFocusNode,
autofocus: true, autofocus: false,
obscureText: false, obscureText: false,
decoration: InputDecoration( decoration: InputDecoration(
isDense: true, isDense: true,

View File

@ -1,3 +1,4 @@
// import 'package:f_r_e_hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart'; import 'package:flutter_animate/flutter_animate.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
@ -93,8 +94,19 @@ class _OptionSelectionModalWidgetState extends State<OptionSelectionModalWidget>
return GestureDetector( return GestureDetector(
onTap: () async { onTap: () async {
Navigator.pop(context); Navigator.pop(context);
if (widget.routesListStr![optionsListIndex] == 'scheduleCompleteVisitPage') {
context.pushNamed(widget.routesListStr![optionsListIndex]); // Navegação para a página ScheduleCompleteVisitPage com queryParameters
context.pushNamed(
'scheduleCompleteVisitPage',
queryParameters: {
'visitStartDateStr': DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
'visitEndDateStr': DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now().add(const Duration(days: 1))),
},
);
} else {
// Navegação para outras páginas
context.pushNamed(widget.routesListStr![optionsListIndex]);
}
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.all(5.0), padding: const EdgeInsets.all(5.0),

View File

@ -96,12 +96,12 @@ class _BottomArrowLinkedLocalsComponentWidgetState
), ),
); );
} }
final gridViewGetLocalsResponse = snapshot.data!; final localsResponse = snapshot.data!;
return Builder( return Builder(
builder: (context) { builder: (context) {
final eachLocals = PhpGroup.getLocalsCall final linkedLocals = PhpGroup.getLocalsCall
.locais( .locais(
gridViewGetLocalsResponse.jsonBody, localsResponse.jsonBody,
) )
?.map((e) => e) ?.map((e) => e)
.toList() .toList()
@ -117,32 +117,48 @@ class _BottomArrowLinkedLocalsComponentWidgetState
childAspectRatio: 1.0, childAspectRatio: 1.0,
), ),
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
itemCount: eachLocals.length, itemCount: linkedLocals.length,
itemBuilder: (context, eachLocalsIndex) { itemBuilder: (context, index) {
final eachLocalsItem = final localItem =
eachLocals[eachLocalsIndex]; linkedLocals[index];
return InkWell( return InkWell(
splashColor: Colors.transparent, splashColor: Colors.transparent,
focusColor: Colors.transparent, focusColor: Colors.transparent,
hoverColor: Colors.transparent, hoverColor: Colors.transparent,
highlightColor: Colors.transparent, highlightColor: Colors.transparent,
onTap: () async { onTap: () async {
if (linkedLocals.any((local) =>
local['CLI_ID'] == FFAppState().cliUUID &&
local['CLU_STATUS'] == "A")) {
FFAppState().cliUUID = getJsonField( FFAppState().cliUUID = getJsonField(
eachLocalsItem, localItem,
r'''$.CLI_ID''', r'''$.CLI_ID''',
).toString(); ).toString();
setState(() {}); setState(() {});
FFAppState().local = getJsonField( FFAppState().local = getJsonField(
eachLocalsItem, localItem,
r'''$.CLI_NOME''', r'''$.CLI_NOME''',
).toString(); ).toString();
setState(() {}); setState(() {});
FFAppState().ownerUUID = getJsonField( FFAppState().ownerUUID = getJsonField(
eachLocalsItem, localItem,
r'''$.CLU_OWNER_ID''', r'''$.CLU_OWNER_ID''',
).toString(); ).toString();
setState(() {}); setState(() {});
debugPrint('Local: ${FFAppState().local}');
Navigator.pop(context); Navigator.pop(context);
} else {
debugPrint('Local não disponível');
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(
// content: Text(
// 'Local não disponível',
// ),
// ),
// );
}
}, },
child: Container( child: Container(
width: 50.0, width: 50.0,
@ -187,7 +203,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState
), ),
child: Image.network( child: Image.network(
'https://freaccess.com.br/freaccess/Images/Clients/${getJsonField( 'https://freaccess.com.br/freaccess/Images/Clients/${getJsonField(
eachLocalsItem, localItem,
r'''$.CLI_ID''', r'''$.CLI_ID''',
).toString()}.png', ).toString()}.png',
width: double.infinity, width: double.infinity,
@ -203,7 +219,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState
.fromSTEB(0.0, 10.0, 0.0, 0.0), .fromSTEB(0.0, 10.0, 0.0, 0.0),
child: Text( child: Text(
getJsonField( getJsonField(
eachLocalsItem, localItem,
r'''$.CLI_NOME''', r'''$.CLI_NOME''',
).toString(), ).toString(),
style: FlutterFlowTheme.of(context) style: FlutterFlowTheme.of(context)

View File

@ -40,18 +40,15 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
} }
Future scheduleVisitOptAction(BuildContext context) async { Future scheduleVisitOptAction(BuildContext context) async {
await showModalBottomSheet( await showAdaptiveDialog(
isScrollControlled: true,
backgroundColor: Colors.transparent,
enableDrag: false,
context: context, context: context,
builder: (context) { builder: (context) {
return Padding( return Padding(
padding: MediaQuery.viewInsetsOf(context), padding: MediaQuery.viewInsetsOf(context),
child: OptionSelectionModalWidget( child: OptionSelectionModalWidget(
routesListStr: <String>[ routesListStr: <String>[
'scheduleProvisionalVisitPage',
'scheduleCompleteVisitPage', 'scheduleCompleteVisitPage',
'scheduleProvisionalVisitPage',
'fastPassPage', 'fastPassPage',
], ],
iconsListIcon: <IconData>[ iconsListIcon: <IconData>[
@ -118,10 +115,10 @@ class MenuComponentModel extends FlutterFlowModel<MenuComponentWidget> {
} }
Future liberationHistoryOptAction(BuildContext context) async { Future liberationHistoryOptAction(BuildContext context) async {
await showModalBottomSheet( await showAdaptiveDialog(
isScrollControlled: true, // isScrollControlled: true,
backgroundColor: Colors.transparent, // backgroundColor: Colors.transparent,
enableDrag: false, // enableDrag: false,
context: context, context: context,
builder: (context) { builder: (context) {
return Padding( return Padding(

View File

@ -860,22 +860,42 @@ Propriedade */
), ),
), ),
), ),
Align( Row(
alignment: const AlignmentDirectional(0.0, 0.0), mainAxisSize: MainAxisSize.max,
child: FlutterFlowIconButton( mainAxisAlignment: MainAxisAlignment.center,
borderColor: Colors.transparent, crossAxisAlignment: CrossAxisAlignment.center,
borderRadius: 20.0, children: [
borderWidth: 1.0, Text(
buttonSize: 50.0, FFLocalizations.of(context).getVariableText(
fillColor: const Color(0x00FFFFFF), enText: 'Expand',
icon: Icon( ptText: 'Expandir',
Icons.keyboard_arrow_down_outlined, ),
color: FlutterFlowTheme.of(context).primary, style: FlutterFlowTheme.of(context).title1.override(
fontFamily: 'Nunito',
color: FlutterFlowTheme.of(context).primaryText,
fontSize: 12.0,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
),
), ),
onPressed: () async { Align(
await widget.changeMenuStyle?.call(); alignment: const AlignmentDirectional(0.0, 0.0),
}, child: FlutterFlowIconButton(
), borderColor: Colors.transparent,
borderRadius: 20.0,
borderWidth: 0.0,
buttonSize: 50.0,
fillColor: const Color(0x00FFFFFF),
icon: Icon(
Icons.keyboard_arrow_down_outlined,
color: FlutterFlowTheme.of(context).primary,
),
onPressed: () async {
await widget.changeMenuStyle?.call();
},
),
),
],
), ),
], ],
); );

View File

@ -904,22 +904,42 @@ Propriedade */
), ),
), ),
alignment: const AlignmentDirectional(0.0, 0.0), alignment: const AlignmentDirectional(0.0, 0.0),
child: Align( child: Row(
alignment: const AlignmentDirectional(0.0, 0.0), crossAxisAlignment: CrossAxisAlignment.center,
child: FlutterFlowIconButton( mainAxisAlignment: MainAxisAlignment.center,
borderColor: Colors.transparent, mainAxisSize: MainAxisSize.max,
borderRadius: 20.0, children: [
borderWidth: 1.0, Text(
buttonSize: 50.0, FFLocalizations.of(context).getVariableText(
fillColor: const Color(0x00FFFFFF), enText: 'Minimize',
icon: Icon( ptText: 'Minimizar',
Icons.keyboard_arrow_up_sharp, ),
color: FlutterFlowTheme.of(context).primary, style: FlutterFlowTheme.of(context).title1.override(
fontFamily: 'Nunito',
color: FlutterFlowTheme.of(context).primaryText,
fontSize: 12.0,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
),
), ),
onPressed: () async { Align(
await widget.changeMenuStyleAction?.call(); alignment: const AlignmentDirectional(0.0, 0.0),
}, child: FlutterFlowIconButton(
), borderColor: Colors.transparent,
borderRadius: 20.0,
borderWidth: 1.0,
buttonSize: 50.0,
fillColor: const Color(0x00FFFFFF),
icon: Icon(
Icons.keyboard_arrow_up_sharp,
color: FlutterFlowTheme.of(context).primary,
),
onPressed: () async {
await widget.changeMenuStyleAction?.call();
},
),
),
],
), ),
), ),
), ),

View File

@ -88,6 +88,10 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter(
name: 'scheduleCompleteVisitPage', name: 'scheduleCompleteVisitPage',
path: '/scheduleCompleteVisitPage', path: '/scheduleCompleteVisitPage',
builder: (context, params) => ScheduleCompleteVisitPageWidget( builder: (context, params) => ScheduleCompleteVisitPageWidget(
// get current datatime picker dd/mm/aaaa hh:mm:ss
// visitStartDateStr: DateTime.now().toString(),
// post 1 day
// visitEndDateStr: DateTime.now().add(const Duration(days: 1)).toString(),
visitorStrList: params.getParam( visitorStrList: params.getParam(
'visitorStrList', 'visitorStrList',
ParamType.String, ParamType.String,

View File

@ -306,6 +306,7 @@ class _AcessHistoryPageWidgetState extends State<AcessHistoryPageWidget> {
Widget _accessHistoryCardMoleculeWidget( Widget _accessHistoryCardMoleculeWidget(
BuildContext context, dynamic accessHistoryItem) { BuildContext context, dynamic accessHistoryItem) {
debugPrint('Access History Item: $accessHistoryItem');
return CardItemTemplateComponentWidget( return CardItemTemplateComponentWidget(
imageHashMap: Map<String, String>.from({ imageHashMap: Map<String, String>.from({
'key': accessHistoryItem['PES_ID'] ?? '', 'key': accessHistoryItem['PES_ID'] ?? '',
@ -313,28 +314,28 @@ class _AcessHistoryPageWidgetState extends State<AcessHistoryPageWidget> {
}), }),
labelsHashMap: Map<String, String>.from({ labelsHashMap: Map<String, String>.from({
'Nome:': accessHistoryItem['PES_NOME'] ?? '', 'Nome:': accessHistoryItem['PES_NOME'] ?? '',
'Entrada:': accessHistoryItem['ACE_DATAHORA'] ?? '', 'Acesso:': accessHistoryItem['ACE_DATAHORA'] ?? '',
'Setor:': accessHistoryItem['ACI_DESCRICAO'] ?? '', 'Setor:': accessHistoryItem['SET_DESCRICAO'] ?? '',
}), }),
statusHashMap: accessHistoryItem['NOT_STATUS'] == 'L' statusHashMap: accessHistoryItem['PES_TIPO'] == 'O'
? Map<String, Color>.from({ ? Map<String, Color>.from({
FFLocalizations.of(context).getVariableText( FFLocalizations.of(context).getVariableText(
ptText: 'Ativo', ptText: 'Visitado',
enText: 'Active', enText: 'Visited',
): FlutterFlowTheme.of(context).success, ): FlutterFlowTheme.of(context).success,
}) })
: accessHistoryItem['NOT_STATUS'] == 'B' : accessHistoryItem['PES_TIPO'] == 'E'
? Map<String, Color>.from({ ? Map<String, Color>.from({
FFLocalizations.of(context).getVariableText( FFLocalizations.of(context).getVariableText(
ptText: 'Bloqueado', ptText: 'Visitante',
enText: 'Blocked', enText: 'Visitor',
): FlutterFlowTheme.of(context).error, ): FlutterFlowTheme.of(context).warning,
}) })
: Map<String, Color>.from({ : Map<String, Color>.from({
FFLocalizations.of(context).getVariableText( FFLocalizations.of(context).getVariableText(
ptText: 'Pendente', ptText: 'Desconhecido',
enText: 'Pending', enText: 'Unknown',
): FlutterFlowTheme.of(context).warning, ): FlutterFlowTheme.of(context).error,
}), }),
onTapCardItemAction: () async {}); onTapCardItemAction: () async {});
} }

View File

@ -1,4 +1,5 @@
// import 'package:f_r_e_hub/backend/push_notification/pushNotification.dart'; // import 'package:f_r_e_hub/backend/push_notification/pushNotification.dart';
import 'package:f_r_e_hub/actions/actions.dart';
import 'package:f_r_e_hub/backend/push_notification/pushNotificationService.dart'; import 'package:f_r_e_hub/backend/push_notification/pushNotificationService.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
@ -35,14 +36,24 @@ class _HomePageWidgetState extends State<HomePageWidget> {
super.initState(); super.initState();
_model = createModel(context, () => HomePageModel()); _model = createModel(context, () => HomePageModel());
SchedulerBinding.instance.addPostFrameCallback((_) async { SchedulerBinding.instance.addPostFrameCallback((_) async {
await PushNotificationService().initialize(context); await PushNotificationService().initialize(context);
await checkLocals(
context: context,
model: _model,
safeSetState: safeSetState,
);
if (FFAppState().cliUUID == null || FFAppState().cliUUID.isEmpty) { if (FFAppState().cliUUID == null || FFAppState().cliUUID.isEmpty) {
showModalBottomSheet( showModalBottomSheet(
isScrollControlled: true, isScrollControlled: false,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
enableDrag: false, enableDrag: false,
isDismissible: false,
context: context, context: context,
builder: (context) { builder: (context) {
return GestureDetector( return GestureDetector(

View File

@ -136,13 +136,7 @@ class _PeopleOnThePropertyPageWidgetState
child: CachedNetworkImage( child: CachedNetworkImage(
fadeInDuration: const Duration(milliseconds: 500), fadeInDuration: const Duration(milliseconds: 500),
fadeOutDuration: const Duration(milliseconds: 500), fadeOutDuration: const Duration(milliseconds: 500),
imageUrl: valueOrDefault<String>( imageUrl: 'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg',
'https://freaccess.com.br/freaccess/getImage.php?devUUID=${FFAppState().devUUID}&userUUID=${FFAppState().userUUID}&cliID=${FFAppState().cliUUID}&atividade=getFoto&Documento=&tipo=E&Email=${getJsonField(
getPoeplePropertyItem,
r'''$.USU_EMAIL''',
).toString()}',
'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg',
),
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),

View File

@ -100,6 +100,35 @@ class _ScheduleCompleteVisitPageWidgetState
_model.switchValue = true; _model.switchValue = true;
_model.textController3 ??= TextEditingController(); _model.textController3 ??= TextEditingController();
_model.textFieldFocusNode3 ??= FocusNode(); _model.textFieldFocusNode3 ??= FocusNode();
debugPrint('widget.visitStartDateStr: ${DateTime.parse(widget.visitStartDateStr!)}');
debugPrint('widget.visitEndDateStr: ${DateTime.parse(widget.visitEndDateStr!)}');
if (widget.visitEndDateStr != null && widget.visitStartDateStr != null) {
_model.datePicked1 = DateTime.parse(widget.visitStartDateStr!);
_model.datePicked2 = DateTime.parse(widget.visitEndDateStr!);
_model.textController1?.text = DateFormat('dd-MM-yyyy HH:mm:ss').format(DateFormat('yyyy-MM-dd HH:mm:ss').parse(widget.visitStartDateStr!));
_model.textController2?.text = DateFormat('dd-MM-yyyy HH:mm:ss').format(DateFormat('yyyy-MM-dd HH:mm:ss').parse(widget.visitEndDateStr!));;
// _model.textController1?.selection = TextSelection.collapsed(
// _model.textController1?.text =
// dateTimeFormat(
// 'd/M/y H:mm:ss',
// _model.datePicked1,
// locale:
// FFLocalizations.of(context)
// .languageCode,
// );
// _model.textController1
// ?.selection =
// TextSelection.collapsed(
// offset: _model
// .textController1!
// .text
// .length);
// });
}
} }
void _loadMoreVisitHistory() async { void _loadMoreVisitHistory() async {