Merge pull request #18 from FRE-Informatica/fix_register_visitor

FIX: Tela de Cadastro Visitante
This commit is contained in:
Lucas Martin Mota 2024-08-14 16:50:31 -03:00 committed by GitHub
commit e722d9179a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 162 additions and 171 deletions

View File

@ -4,6 +4,7 @@ import 'dart:developer';
import 'package:hub/components/molecular_components/throw_exception/throw_exception_widget.dart';
import 'package:hub/custom_code/actions/convert_image_file_to_base64.dart';
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import 'package:hub/shared/utils/validator_util.dart';
import '/backend/api_requests/api_calls.dart';
import '/flutter_flow/flutter_flow_util.dart';
@ -12,15 +13,13 @@ import 'package:flutter/material.dart';
import 'regisiter_vistor_template_component_widget.dart';
class RegisiterVistorTemplateComponentModel
extends FlutterFlowModel<RegisiterVistorTemplateComponentWidget> {
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([]));
FFUploadedFile uploadedLocalFile = FFUploadedFile(bytes: Uint8List.fromList([]));
void debounce(Function() fn, Duration time) {
if (_debounceTimer != null) {
@ -98,13 +97,7 @@ class RegisiterVistorTemplateComponentModel
TextEditingController? textController4;
String? Function(BuildContext, String?)? textController4Validator;
String? _textController4Validator(BuildContext context, String? val) {
if (val == null || val.isEmpty) {
return FFLocalizations.of(context).getVariableText(
enText: 'This field is required',
ptText: 'Este campo é obrigatório',
);
}
if (!val.contains('@') || !val.contains('.')) {
if (val != null && val.isNotEmpty && ValidatorUtil.isValidEmail(val) == false) {
return FFLocalizations.of(context).getVariableText(
enText: 'Invalid email',
ptText: 'Email inválido',

View File

@ -2,6 +2,7 @@ import 'dart:developer';
import 'package:flutter/services.dart';
import 'package:hub/shared/utils/dialog_util.dart';
import 'package:hub/shared/utils/validator_util.dart';
import 'package:json_path/fun_sdk.dart';
import 'package:rxdart/rxdart.dart';
@ -87,19 +88,15 @@ class _RegisiterVistorTemplateComponentWidgetState
return false;
}
if (_model.textController1.text.isEmpty ||
_model.textController1.text == '') {
if (_model.textController1.text.isEmpty || _model.textController1.text == '') {
return false;
}
if (_model.dropDownValue == null ||
_model.dropDownValue!.isEmpty ||
_model.dropDownValue == '') {
if (_model.dropDownValue == null || _model.dropDownValue!.isEmpty || _model.dropDownValue == '') {
return false;
}
if (_model.textController2.text.isEmpty ||
_model.textController2.text == '') {
if (_model.textController2.text.isEmpty || _model.textController2.text == '') {
return false;
}
@ -107,6 +104,10 @@ class _RegisiterVistorTemplateComponentWidgetState
return false;
}
if (_model.textController4.text.isNotEmpty && _model.textController4.text != '' && ValidatorUtil.isValidEmail(_model.textController4.text) == false) {
return false;
}
return true;
}
@ -129,7 +130,6 @@ class _RegisiterVistorTemplateComponentWidgetState
),
child: SingleChildScrollView(
child: Form(
// key: UniqueKey(),
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(
mainAxisSize: MainAxisSize.min,
@ -138,8 +138,7 @@ class _RegisiterVistorTemplateComponentWidgetState
Align(
alignment: const AlignmentDirectional(-1.0, 0.0),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
20.0, 30.0, 0.0, 15.0),
padding: const EdgeInsetsDirectional.fromSTEB(20.0, 0.0, 0.0, 15.0),
child: Text(
FFLocalizations.of(context).getText(
'zazj5d8b' /* Preencha o formulário com os d... */,
@ -368,8 +367,7 @@ class _RegisiterVistorTemplateComponentWidgetState
),
maxLines: null,
keyboardType: TextInputType.name,
validator:
_model.textController1Validator.asValidator(context),
validator: _model.textController1Validator.asValidator(context),
),
),
Padding(
@ -455,160 +453,162 @@ class _RegisiterVistorTemplateComponentWidgetState
],
),
),
Builder(
builder: (context) {
if ((_model.uploadedLocalFile.bytes?.isNotEmpty ?? false)) {
return InkWell(
splashColor: Colors.transparent,
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () async {
setState(() {
_model.isDataUploading = false;
_model.uploadedLocalFile =
FFUploadedFile(bytes: Uint8List.fromList([]));
});
},
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.memory(
_model.uploadedLocalFile.bytes ??
Uint8List.fromList([]),
width: 300.0,
height: 200.0,
fit: BoxFit.cover,
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(24.0, 0.0, 24.0, 0.0),
child: Builder(
builder: (context) {
if ((_model.uploadedLocalFile.bytes?.isNotEmpty ?? false)) {
return InkWell(
splashColor: Colors.transparent,
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () async {
setState(() {
_model.isDataUploading = false;
_model.uploadedLocalFile =
FFUploadedFile(bytes: Uint8List.fromList([]));
});
},
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.memory(
_model.uploadedLocalFile.bytes ??
Uint8List.fromList([]),
width: 300.0,
height: 200.0,
fit: BoxFit.cover,
),
),
),
);
} else {
return Stack(
children: [
Align(
alignment: const AlignmentDirectional(0.01, 0.0),
child: FFButtonWidget(
onPressed: () async {
final selectedMedia =
await selectMediaWithSourceBottomSheet(
context: context,
// maxWidth: 300.00,
// maxHeight: 300.00,
imageQuality: 100,
allowPhoto: true,
includeDimensions: true,
);
if (selectedMedia != null) {
// &&
// selectedMedia.every((m) =>
// validateFileFormat(
// m.storagePath, context))) {
setState(() => _model.isDataUploading = true);
var selectedUploadedFiles =
<FFUploadedFile>[];
);
} else {
return Stack(
children: [
Align(
alignment: const AlignmentDirectional(0.0, 0.0),
child: FFButtonWidget(
onPressed: () async {
final selectedMedia =
await selectMediaWithSourceBottomSheet(
context: context,
// maxWidth: 300.00,
// maxHeight: 300.00,
imageQuality: 100,
allowPhoto: true,
includeDimensions: true,
);
if (selectedMedia != null) {
// &&
// selectedMedia.every((m) =>
// validateFileFormat(
// m.storagePath, context))) {
setState(() => _model.isDataUploading = true);
var selectedUploadedFiles =
<FFUploadedFile>[];
try {
showUploadMessage(
context,
'Uploading file...',
showLoading: true,
);
selectedUploadedFiles = selectedMedia
.map((m) => FFUploadedFile(
name:
m.storagePath.split('/').last,
bytes: m.bytes,
height: m.dimensions?.height,
width: m.dimensions?.width,
// blurHash: m.blurHash,
))
.toList();
} finally {
ScaffoldMessenger.of(context)
.hideCurrentSnackBar();
_model.isDataUploading = false;
try {
showUploadMessage(
context,
'Uploading file...',
showLoading: true,
);
selectedUploadedFiles = selectedMedia
.map((m) => FFUploadedFile(
name:
m.storagePath.split('/').last,
bytes: m.bytes,
height: m.dimensions?.height,
width: m.dimensions?.width,
// blurHash: m.blurHash,
))
.toList();
} finally {
ScaffoldMessenger.of(context)
.hideCurrentSnackBar();
_model.isDataUploading = false;
}
if (selectedUploadedFiles.length ==
selectedMedia.length) {
setState(() {
_model.uploadedLocalFile =
selectedUploadedFiles.first;
});
showUploadMessage(context, 'Success!');
} else {
setState(() {});
showUploadMessage(
context, 'Failed to upload data');
return;
}
}
if (selectedUploadedFiles.length ==
selectedMedia.length) {
setState(() {
_model.uploadedLocalFile =
selectedUploadedFiles.first;
});
showUploadMessage(context, 'Success!');
} else {
setState(() {});
showUploadMessage(
context, 'Failed to upload data');
return;
}
}
},
text: '',
icon: Icon(
Icons.photo_camera,
color: FlutterFlowTheme.of(context).accent1,
size: 30.0,
),
options: FFButtonOptions(
width: 300.0,
height: 80.0,
padding: const EdgeInsetsDirectional.fromSTEB(
0.0, 0.0, 0.0, 0.0),
iconPadding:
const EdgeInsetsDirectional.fromSTEB(
14.0, 0.0, 0.0, 20.0),
color: FlutterFlowTheme.of(context)
.primaryBackground,
textStyle: FlutterFlowTheme.of(context)
.titleSmall
.override(
fontFamily: FlutterFlowTheme.of(context)
.titleSmallFamily,
color: FlutterFlowTheme.of(context)
.primaryText,
fontSize: 16.0,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap()
.containsKey(
FlutterFlowTheme.of(context)
.titleSmallFamily),
),
borderSide: BorderSide(
},
text: '',
icon: Icon(
Icons.photo_camera,
color: FlutterFlowTheme.of(context).accent1,
width: 0.2,
size: 30.0,
),
options: FFButtonOptions(
width: double.infinity,
height: 120.0,
padding: const EdgeInsetsDirectional.fromSTEB(0.0, 0.0, 0.0, 20.0),
iconPadding:
const EdgeInsetsDirectional.fromSTEB(
14.0, 0.0, 0.0, 20.0),
color: FlutterFlowTheme.of(context)
.primaryBackground,
textStyle: FlutterFlowTheme.of(context)
.titleSmall
.override(
fontFamily: FlutterFlowTheme.of(context)
.titleSmallFamily,
color: FlutterFlowTheme.of(context)
.primaryText,
fontSize: 16.0,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap()
.containsKey(
FlutterFlowTheme.of(context)
.titleSmallFamily),
),
borderSide: BorderSide(
color: FlutterFlowTheme.of(context).accent1,
width: 0.2,
),
borderRadius: BorderRadius.circular(8.0),
),
borderRadius: BorderRadius.circular(8.0),
),
),
),
Align(
alignment: const AlignmentDirectional(0.0, 0.0),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
0.0, 50.0, 0.0, 0.0),
child: Text(
FFLocalizations.of(context).getText(
'p4ftwxcy' /* Clique para adicionar a foto p... */,
Align(
alignment: const AlignmentDirectional(0.0, 0.0),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
10.0, 65.0, 10.0, 0.0),
child: Text(
FFLocalizations.of(context).getText(
'p4ftwxcy' /* Clique para adicionar a foto p... */,
),
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.bodyMediumFamily,
color: FlutterFlowTheme.of(context)
.primaryText,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap()
.containsKey(
FlutterFlowTheme.of(context)
.bodyMediumFamily),
),
),
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily: FlutterFlowTheme.of(context)
.bodyMediumFamily,
color: FlutterFlowTheme.of(context)
.primaryText,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap()
.containsKey(
FlutterFlowTheme.of(context)
.bodyMediumFamily),
),
),
),
),
],
);
}
},
],
);
}
},
),
),
Align(
alignment: const AlignmentDirectional(-1.0, 0.0),
@ -792,13 +792,11 @@ class _RegisiterVistorTemplateComponentWidgetState
FlutterFlowTheme.of(context).bodyMediumFamily),
),
keyboardType: TextInputType.emailAddress,
// validator:
// _model.textController4Validator.asValidator(context),
validator: _model.textController4Validator.asValidator(context),
),
),
Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(0.0, 65.0, 0.0, 0.0),
padding: const EdgeInsetsDirectional.fromSTEB(0.0, 65.0, 0.0, 0.0),
child: FFButtonWidget(
onPressed: _isFormValid(context)
? () async {