Skip to content

Instantly share code, notes, and snippets.

@callmephil
Created January 17, 2025 22:07
Show Gist options
  • Save callmephil/3bbabaab51fa7f7de6c298d6d120df97 to your computer and use it in GitHub Desktop.
Save callmephil/3bbabaab51fa7f7de6c298d6d120df97 to your computer and use it in GitHub Desktop.
dynamic input validation demo.
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