-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InputDecoration labelText doesn't turn red when TextFormField validation fails #41382
Comments
Please provide the output of |
Flutter Doctor (-v) output[√] Flutter (Channel stable, v1.9.1+hotfix.2, on Microsoft Windows [Versione 10.0.18362.356], locale it-IT) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [√] Android Studio (version 3.5) [√] VS Code (version 1.38.1) You can find the app here. It's a simple screen with the custom Thanks |
Hi @belfed |
Hi @belfed import 'package:flutter/material.dart';
/// [https://flutter.dev/docs/cookbook/forms/validation#interactive-example]
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appTitle = 'Form Validation Demo';
return MaterialApp(
title: appTitle,
home: Scaffold(
// appBar: AppBar(
// title: Text(appTitle),
// ),
body: MyCustomForm(),
),
);
}
}
// Create a Form widget.
class MyCustomForm extends StatefulWidget {
@override
MyCustomFormState createState() {
return MyCustomFormState();
}
}
// Create a corresponding State class.
// This class holds data related to the form.
class MyCustomFormState extends State<MyCustomForm> {
// Create a global key that uniquely identifies the Form widget
// and allows validation of the form.
//
// Note: This is a GlobalKey<FormState>,
// not a GlobalKey<MyCustomFormState>.
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
// Build a Form widget using the _formKey created above.
return Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextFormField(
/// [https://flutter.dev/docs/cookbook/forms/text-input]
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.teal),
),
hintText: 'Enter a search term',
labelText: 'Enter a search term',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: RaisedButton(
onPressed: () {
// Validate returns true if the form is valid, or false
// otherwise.
if (_formKey.currentState.validate()) {
// If the form is valid, display a Snackbar.
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text('Processing Data')));
}
},
child: Text('Submit'),
),
),
],
),
);
}
} I feel safe to close this issue, |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Details
I'm having troubles with the
TextFormField
labelText
parameter. I have this custom widget that wraps aTextFormField
with some styles and features in order to use it quickly accross the application and I changed thelabelText
color in thedecoration
parameter and it works just fine.However, when the validation method fails (I check if the inserted text is an e-mail address), the
TextFormField
border turns red, as well as the error message, but thelabelText
color remains the same (grey in this case) instead of turning red.At first I thought I had to style the error
labelText
in order to get the color I wanted, but I noticed that if I don't set thelabelText
color, it turns red when the validation fails. It seems that if you change the color you cannot handle it depending on the validation result.Is this some kind of glitch?
Thank you for the help.
The text was updated successfully, but these errors were encountered: