fix: add form validador
This commit is contained in:
parent
1ee6c90520
commit
0b57716abe
|
@ -52,8 +52,8 @@ Future<List<SelectedFile>?> selectMediaWithSourceBottomSheet({
|
||||||
required bool allowPhoto,
|
required bool allowPhoto,
|
||||||
bool allowVideo = false,
|
bool allowVideo = false,
|
||||||
String pickerFontFamily = 'Roboto',
|
String pickerFontFamily = 'Roboto',
|
||||||
Color textColor = const Color(0xFF111417),
|
// Color textColor = const Color(0xFF111417),
|
||||||
Color backgroundColor = const Color(0xFFF5F5F5),
|
// Color backgroundColor = const Color(0xFFF5F5F5),
|
||||||
bool includeDimensions = false,
|
bool includeDimensions = false,
|
||||||
bool includeBlurHash = false,
|
bool includeBlurHash = false,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -63,12 +63,12 @@ Future<List<SelectedFile>?> selectMediaWithSourceBottomSheet({
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: GoogleFonts.getFont(
|
style: GoogleFonts.getFont(
|
||||||
pickerFontFamily,
|
pickerFontFamily,
|
||||||
color: textColor,
|
color: FlutterFlowTheme.of(context).primaryText,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
tileColor: backgroundColor,
|
tileColor: FlutterFlowTheme.of(context).primaryBackground,
|
||||||
dense: false,
|
dense: false,
|
||||||
onTap: () => Navigator.pop(
|
onTap: () => Navigator.pop(
|
||||||
context,
|
context,
|
||||||
|
@ -77,7 +77,7 @@ Future<List<SelectedFile>?> selectMediaWithSourceBottomSheet({
|
||||||
);
|
);
|
||||||
final mediaSource = await showModalBottomSheet<MediaSource>(
|
final mediaSource = await showModalBottomSheet<MediaSource>(
|
||||||
context: context,
|
context: context,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
@ -91,13 +91,13 @@ Future<List<SelectedFile>?> selectMediaWithSourceBottomSheet({
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: GoogleFonts.getFont(
|
style: GoogleFonts.getFont(
|
||||||
pickerFontFamily,
|
pickerFontFamily,
|
||||||
color: textColor.withOpacity(0.65),
|
color: FlutterFlowTheme.of(context).primaryText.withOpacity(0.65),
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
tileColor: backgroundColor,
|
tileColor: FlutterFlowTheme.of(context).primaryBackground,
|
||||||
dense: false,
|
dense: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
|
|
@ -17,10 +17,28 @@ class RegisterVisitorPageModel
|
||||||
FocusNode? textFieldFocusNode1;
|
FocusNode? textFieldFocusNode1;
|
||||||
TextEditingController? textController1;
|
TextEditingController? textController1;
|
||||||
String? Function(BuildContext, String?)? textController1Validator;
|
String? Function(BuildContext, String?)? textController1Validator;
|
||||||
|
String? _textController1Validator(BuildContext context, String? val) {
|
||||||
|
if (val == null || val.isEmpty) {
|
||||||
|
return FFLocalizations.of(context).getVariableText(
|
||||||
|
enText: 'This field is required',
|
||||||
|
ptText: 'Este campo é obrigatório',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// State field(s) for TextField widget.
|
// State field(s) for TextField widget.
|
||||||
FocusNode? textFieldFocusNode2;
|
FocusNode? textFieldFocusNode2;
|
||||||
TextEditingController? textController2;
|
TextEditingController? textController2;
|
||||||
String? Function(BuildContext, String?)? textController2Validator;
|
String? Function(BuildContext, String?)? textController2Validator;
|
||||||
|
String? _textController2Validator(BuildContext context, String? val) {
|
||||||
|
if (val == null || val.isEmpty) {
|
||||||
|
return FFLocalizations.of(context).getVariableText(
|
||||||
|
enText: 'This field is required',
|
||||||
|
ptText: 'Este campo é obrigatório',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// State field(s) for DropDown widget.
|
// State field(s) for DropDown widget.
|
||||||
String? dropDownValue;
|
String? dropDownValue;
|
||||||
FormFieldController<String>? dropDownValueController;
|
FormFieldController<String>? dropDownValueController;
|
||||||
|
@ -28,17 +46,56 @@ class RegisterVisitorPageModel
|
||||||
FocusNode? textFieldFocusNode3;
|
FocusNode? textFieldFocusNode3;
|
||||||
TextEditingController? textController3;
|
TextEditingController? textController3;
|
||||||
String? Function(BuildContext, String?)? textController3Validator;
|
String? Function(BuildContext, String?)? textController3Validator;
|
||||||
|
String? _textController3Validator(BuildContext context, String? val) {
|
||||||
|
if (val == null || val.isEmpty) {
|
||||||
|
return FFLocalizations.of(context).getVariableText(
|
||||||
|
enText: 'This field is required',
|
||||||
|
ptText: 'Este campo é obrigatório',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// State field(s) for TextField widget.
|
// State field(s) for TextField widget.
|
||||||
FocusNode? textFieldFocusNode4;
|
FocusNode? textFieldFocusNode4;
|
||||||
TextEditingController? textController4;
|
TextEditingController? textController4;
|
||||||
String? Function(BuildContext, String?)? textController4Validator;
|
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',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// Stores action output result for [Custom Action - convertImageFileToBase64] action in Button widget.
|
// Stores action output result for [Custom Action - convertImageFileToBase64] action in Button widget.
|
||||||
String? imgBase64;
|
String? imgBase64;
|
||||||
// Stores action output result for [Backend Call - API (postScheduleVisitor)] action in Button widget.
|
// Stores action output result for [Backend Call - API (postScheduleVisitor)] action in Button widget.
|
||||||
ApiCallResponse? scheduleVisitor;
|
ApiCallResponse? scheduleVisitor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState(BuildContext context) {}
|
void initState(BuildContext context) {
|
||||||
|
|
||||||
|
textFieldFocusNode1 = FocusNode();
|
||||||
|
textController1 = TextEditingController();
|
||||||
|
textController1Validator = _textController1Validator;
|
||||||
|
|
||||||
|
textFieldFocusNode2 = FocusNode();
|
||||||
|
textController2 = TextEditingController();
|
||||||
|
textController2Validator = _textController2Validator;
|
||||||
|
|
||||||
|
|
||||||
|
dropDownValue = '';
|
||||||
|
// dropDownValueController = FormFieldController<String>(initialValue: dropDownValue);
|
||||||
|
|
||||||
|
textFieldFocusNode3 = FocusNode();
|
||||||
|
textController3 = TextEditingController();
|
||||||
|
textController3Validator = _textController3Validator;
|
||||||
|
|
||||||
|
textFieldFocusNode4 = FocusNode();
|
||||||
|
textController4 = TextEditingController();
|
||||||
|
textController4Validator = _textController4Validator;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
|
|
@ -116,6 +116,9 @@ class _RegisterVisitorPageWidgetState extends State<RegisterVisitorPageWidget> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
|
child: Form(
|
||||||
|
// key: UniqueKey(),
|
||||||
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
@ -474,7 +477,9 @@ class _RegisterVisitorPageWidgetState extends State<RegisterVisitorPageWidget> {
|
||||||
child: Container(
|
child: Container(
|
||||||
width: MediaQuery.sizeOf(context).width * 0.95,
|
width: MediaQuery.sizeOf(context).width * 0.95,
|
||||||
decoration: const BoxDecoration(),
|
decoration: const BoxDecoration(),
|
||||||
child: Row(
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
@ -549,12 +554,32 @@ class _RegisterVisitorPageWidgetState extends State<RegisterVisitorPageWidget> {
|
||||||
isOverButton: true,
|
isOverButton: true,
|
||||||
isSearchable: false,
|
isSearchable: false,
|
||||||
isMultiSelect: false,
|
isMultiSelect: false,
|
||||||
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
.divide(const SizedBox(width: 19.0))
|
.divide(const SizedBox(width: 19.0))
|
||||||
.addToStart(const SizedBox(width: 30.0)),
|
.addToStart(const SizedBox(width: 30.0)),
|
||||||
),
|
),
|
||||||
|
if (_model.dropDownValue == null ||
|
||||||
|
_model.dropDownValue == '')
|
||||||
|
Align(
|
||||||
|
alignment: const AlignmentDirectional(0.4, 0),
|
||||||
|
child: Text(FFLocalizations.of(context).getVariableText(
|
||||||
|
enText: 'This field is required',
|
||||||
|
ptText: 'Este campo é obrigatório',
|
||||||
|
),
|
||||||
|
style: FlutterFlowTheme.of(context).bodySmall.override(
|
||||||
|
fontFamily: FlutterFlowTheme.of(context)
|
||||||
|
.bodySmallFamily,
|
||||||
|
color: FlutterFlowTheme.of(context).error,
|
||||||
|
letterSpacing: 0.0,
|
||||||
|
useGoogleFonts: GoogleFonts.asMap().containsKey(
|
||||||
|
FlutterFlowTheme.of(context).bodySmallFamily),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
|
@ -773,7 +798,27 @@ class _RegisterVisitorPageWidgetState extends State<RegisterVisitorPageWidget> {
|
||||||
nome: 'Test',
|
nome: 'Test',
|
||||||
tipo: 'V',
|
tipo: 'V',
|
||||||
foto: 'base64;jpeg,klajsalkjslkajslkajl',
|
foto: 'base64;jpeg,klajsalkjslkajslkajl',
|
||||||
|
).onError((e, s) async {
|
||||||
|
return await showAdaptiveDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () => Navigator.pop(context),
|
||||||
|
child: Padding(
|
||||||
|
padding: MediaQuery.viewInsetsOf(context),
|
||||||
|
child: Dialog(
|
||||||
|
child: ThrowExceptionWidget(
|
||||||
|
msg: FFLocalizations.of(context).getVariableText(
|
||||||
|
ptText: 'Você esqueceu de adicionar algum dado obrigatório. Verifique se a imagem, nome, tipo e documento foram preenchidos corretamente.',
|
||||||
|
enText: 'You forgot to add some required data. Check if the image, name, type and document were filled in correctly.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
if (PhpGroup.postScheduleVisitorCall.error(
|
if (PhpGroup.postScheduleVisitorCall.error(
|
||||||
(_model.scheduleVisitor?.jsonBody ?? ''),
|
(_model.scheduleVisitor?.jsonBody ?? ''),
|
||||||
|
@ -789,10 +834,7 @@ class _RegisterVisitorPageWidgetState extends State<RegisterVisitorPageWidget> {
|
||||||
_model.dropDownValueController?.reset();
|
_model.dropDownValueController?.reset();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await showModalBottomSheet(
|
await showAdaptiveDialog(
|
||||||
isScrollControlled: true,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
enableDrag: false,
|
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
@ -804,12 +846,13 @@ class _RegisterVisitorPageWidgetState extends State<RegisterVisitorPageWidget> {
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding:
|
padding:
|
||||||
MediaQuery.viewInsetsOf(context),
|
MediaQuery.viewInsetsOf(context),
|
||||||
|
child: Dialog(
|
||||||
child: ThrowExceptionWidget(
|
child: ThrowExceptionWidget(
|
||||||
msg:
|
msg:FFLocalizations.of(context).getVariableText(
|
||||||
'\\devUUID=${FFAppState().devUUID}\\userUUID=${FFAppState().userUUID}\\cliID=${FFAppState().cliUUID}\\Documento=${_model.textController2.text}\\Nome=${_model.textController1.text}\\dropdown${_model.dropDownValue}\\${PhpGroup.postScheduleVisitorCall.errorMsg(
|
ptText: 'Erro ao cadastrar visitante. Tente novamente.',
|
||||||
(_model.scheduleVisitor?.jsonBody ??
|
enText: 'Error registering visitor. Try again.',
|
||||||
''),
|
),
|
||||||
)}',
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -817,23 +860,20 @@ class _RegisterVisitorPageWidgetState extends State<RegisterVisitorPageWidget> {
|
||||||
).then((value) => safeSetState(() {}));
|
).then((value) => safeSetState(() {}));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await showModalBottomSheet(
|
await showAdaptiveDialog(
|
||||||
isScrollControlled: true,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
enableDrag: false,
|
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => _model
|
onTap: () => Navigator.pop(context),
|
||||||
.unfocusNode.canRequestFocus
|
|
||||||
? FocusScope.of(context)
|
|
||||||
.requestFocus(_model.unfocusNode)
|
|
||||||
: FocusScope.of(context).unfocus(),
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: MediaQuery.viewInsetsOf(context),
|
padding: MediaQuery.viewInsetsOf(context),
|
||||||
|
child: Dialog(
|
||||||
child: ThrowExceptionWidget(
|
child: ThrowExceptionWidget(
|
||||||
msg:
|
msg: FFLocalizations.of(context).getVariableText(
|
||||||
'Você esqueceu de adicionar algum dado obrigatório. Verifique se a imagem, nome, tipo e documento estão foram preenchidos corretamente.- devUUID=${FFAppState().devUUID}- userUUID=${FFAppState().userUUID}- cliID=${FFAppState().cliUUID}- Documento=${_model.textController2.text}- Nome=${_model.textController1.text}- Tipo=${_model.dropDownValue}',
|
ptText: 'Você esqueceu de adicionar algum dado obrigatório. Verifique se a imagem, nome, tipo e documento foram preenchidos corretamente.',
|
||||||
|
enText: 'You forgot to add some required data. Check if the image, name, type and document were filled in correctly.',
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -888,6 +928,7 @@ class _RegisterVisitorPageWidgetState extends State<RegisterVisitorPageWidget> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue