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 '/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 '/flutter_flow/flutter_flow_theme.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;
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(
BuildContext context,
String status,
@ -436,4 +492,6 @@ Future changeStatusAction(
default:
break;
}
}

View File

@ -222,7 +222,7 @@ class _OptModalWidgetState extends State<OptModalWidget> {
child: TextFormField(
controller: _model.textController,
focusNode: _model.textFieldFocusNode,
autofocus: true,
autofocus: false,
obscureText: false,
decoration: InputDecoration(
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_animate/flutter_animate.dart';
import 'package:google_fonts/google_fonts.dart';
@ -93,8 +94,19 @@ class _OptionSelectionModalWidgetState extends State<OptionSelectionModalWidget>
return GestureDetector(
onTap: () async {
Navigator.pop(context);
context.pushNamed(widget.routesListStr![optionsListIndex]);
if (widget.routesListStr![optionsListIndex] == 'scheduleCompleteVisitPage') {
// 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(
padding: const EdgeInsets.all(5.0),

View File

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

View File

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

View File

@ -860,22 +860,42 @@ Propriedade */
),
),
),
Align(
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_down_outlined,
color: FlutterFlowTheme.of(context).primary,
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
FFLocalizations.of(context).getVariableText(
enText: 'Expand',
ptText: 'Expandir',
),
style: FlutterFlowTheme.of(context).title1.override(
fontFamily: 'Nunito',
color: FlutterFlowTheme.of(context).primaryText,
fontSize: 12.0,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
),
),
onPressed: () async {
await widget.changeMenuStyle?.call();
},
),
Align(
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),
child: Align(
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,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Text(
FFLocalizations.of(context).getVariableText(
enText: 'Minimize',
ptText: 'Minimizar',
),
style: FlutterFlowTheme.of(context).title1.override(
fontFamily: 'Nunito',
color: FlutterFlowTheme.of(context).primaryText,
fontSize: 12.0,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.normal,
),
),
onPressed: () async {
await widget.changeMenuStyleAction?.call();
},
),
Align(
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',
path: '/scheduleCompleteVisitPage',
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',
ParamType.String,

View File

@ -306,6 +306,7 @@ class _AcessHistoryPageWidgetState extends State<AcessHistoryPageWidget> {
Widget _accessHistoryCardMoleculeWidget(
BuildContext context, dynamic accessHistoryItem) {
debugPrint('Access History Item: $accessHistoryItem');
return CardItemTemplateComponentWidget(
imageHashMap: Map<String, String>.from({
'key': accessHistoryItem['PES_ID'] ?? '',
@ -313,28 +314,28 @@ class _AcessHistoryPageWidgetState extends State<AcessHistoryPageWidget> {
}),
labelsHashMap: Map<String, String>.from({
'Nome:': accessHistoryItem['PES_NOME'] ?? '',
'Entrada:': accessHistoryItem['ACE_DATAHORA'] ?? '',
'Setor:': accessHistoryItem['ACI_DESCRICAO'] ?? '',
'Acesso:': accessHistoryItem['ACE_DATAHORA'] ?? '',
'Setor:': accessHistoryItem['SET_DESCRICAO'] ?? '',
}),
statusHashMap: accessHistoryItem['NOT_STATUS'] == 'L'
statusHashMap: accessHistoryItem['PES_TIPO'] == 'O'
? Map<String, Color>.from({
FFLocalizations.of(context).getVariableText(
ptText: 'Ativo',
enText: 'Active',
ptText: 'Visitado',
enText: 'Visited',
): FlutterFlowTheme.of(context).success,
})
: accessHistoryItem['NOT_STATUS'] == 'B'
: accessHistoryItem['PES_TIPO'] == 'E'
? Map<String, Color>.from({
FFLocalizations.of(context).getVariableText(
ptText: 'Bloqueado',
enText: 'Blocked',
): FlutterFlowTheme.of(context).error,
ptText: 'Visitante',
enText: 'Visitor',
): FlutterFlowTheme.of(context).warning,
})
: Map<String, Color>.from({
FFLocalizations.of(context).getVariableText(
ptText: 'Pendente',
enText: 'Pending',
): FlutterFlowTheme.of(context).warning,
ptText: 'Desconhecido',
enText: 'Unknown',
): FlutterFlowTheme.of(context).error,
}),
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/actions/actions.dart';
import 'package:f_r_e_hub/backend/push_notification/pushNotificationService.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
@ -35,14 +36,24 @@ class _HomePageWidgetState extends State<HomePageWidget> {
super.initState();
_model = createModel(context, () => HomePageModel());
SchedulerBinding.instance.addPostFrameCallback((_) async {
await PushNotificationService().initialize(context);
await checkLocals(
context: context,
model: _model,
safeSetState: safeSetState,
);
if (FFAppState().cliUUID == null || FFAppState().cliUUID.isEmpty) {
showModalBottomSheet(
isScrollControlled: true,
isScrollControlled: false,
backgroundColor: Colors.transparent,
enableDrag: false,
isDismissible: false,
context: context,
builder: (context) {
return GestureDetector(

View File

@ -136,13 +136,7 @@ class _PeopleOnThePropertyPageWidgetState
child: CachedNetworkImage(
fadeInDuration: const Duration(milliseconds: 500),
fadeOutDuration: const Duration(milliseconds: 500),
imageUrl: valueOrDefault<String>(
'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',
),
imageUrl: 'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg',
fit: BoxFit.cover,
),
),

View File

@ -100,6 +100,35 @@ class _ScheduleCompleteVisitPageWidgetState
_model.switchValue = true;
_model.textController3 ??= TextEditingController();
_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 {