Created
January 17, 2025 22:07
-
-
Save callmephil/3bbabaab51fa7f7de6c298d6d120df97 to your computer and use it in GitHub Desktop.
dynamic input validation demo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SizedBox( | |
height: 200, | |
child: Form( | |
key: _formKey, | |
child: TextFormField( | |
controller: _ec, | |
maxLines: null, | |
expands: false, | |
onChanged: (value) { | |
// Trigger immediate validation on text change | |
if (_formKey.currentState != null && | |
value.isNotEmpty) { | |
_formKey.currentState!.validate(); | |
} | |
}, | |
validator: (text) { | |
if (text == null || text.isEmpty) { | |
return 'Text is empty'; | |
} | |
return null; | |
}, | |
onEditingComplete: () {}, | |
decoration: InputDecoration( | |
border: OutlineInputBorder(), | |
labelText: 'Even Densed TextFiled', | |
isCollapsed: true, // Added this | |
contentPadding: EdgeInsets.all(12), // Added this | |
prefixIcon: Icon(Icons.search), | |
suffixIcon: IconButton( | |
onPressed: () { | |
if (_formKey.currentState?.validate() ?? | |
false) { | |
// TODO submit | |
} | |
}, | |
icon: Icon(Icons.abc), | |
), | |
), | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment