1

This is My Custom validation textfield

CmnTextField(
 labelText: "Location",
 controller: LocationController,
 readOnly: true,
 autoValidateMode: controller.unit
 ? AutovalidateMode.always
 : AutovalidateMode.disabled,
 onTap: () async {
 final result = await Navigator.of(context).push(MaterialPageRoute(
 builder: (_) => SelectLocation(whichLocation: 'From Location')));
 if (result != null && result is Locations) {
 _assignFromLocation(result);
 }
 },
 validator: _validateInput,
 enabled: isEdit
 ? false
 : controller.isMove ||
 controller.isCustomMove ||
 controller.unit,
 ),

This is my validation Function:

String? _validateInput(String? value) {
 if (controller.unit) {
 if (value == null || value.isEmpty) {
 return 'required';
 }
 }
 return null;
 }

When controller.unit this is condition is true make disable textfield and remove validation and when this condition is false at time i need on autovalidation mode so how i can achieve this?

if anyone have any idea then tell me

asked Dec 6, 2024 at 9:18
6
  • apply some code if your controller.unit is null validator: controller.unit ? null : _validateInput, Commented Dec 6, 2024 at 9:25
  • 1
    Then textfield autovalidation not working Commented Dec 6, 2024 at 9:30
  • Have you tried GlobalKey<FormState> key with Form widget? Commented Dec 6, 2024 at 10:29
  • Try to wrap CmnTextField with Form widget. Commented Dec 6, 2024 at 10:35
  • yes it's already added still not working, you have any other solution? Commented Dec 6, 2024 at 10:53

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.