Skip to content
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

Closed
belfed opened this issue Sep 26, 2019 · 5 comments
Closed
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Comments

@belfed
Copy link

belfed commented Sep 26, 2019

Details

I'm having troubles with the TextFormField labelText parameter. I have this custom widget that wraps a TextFormField with some styles and features in order to use it quickly accross the application and I changed the labelText color in the decoration 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 the labelText color remains the same (grey in this case) instead of turning red.

textformfield

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 the labelText 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.

@BondarenkoStas BondarenkoStas added the framework flutter/packages/flutter repository. See also f: labels. label Sep 26, 2019
@HansMuller HansMuller added the f: material design flutter/packages/flutter/material repository. label Sep 27, 2019
@HansMuller
Copy link
Contributor

Please provide the output of flutter doctor and a small self-contained app that demonstrates the problem and we'll look into it. Note also: https://gist.github.com/ is a useful way to share the code.

@HansMuller HansMuller added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 27, 2019
@belfed
Copy link
Author

belfed commented Sep 27, 2019

Flutter Doctor (-v) output

[√] Flutter (Channel stable, v1.9.1+hotfix.2, on Microsoft Windows [Versione 10.0.18362.356], locale it-IT)
• Flutter version 1.9.1+hotfix.2 at C:\Flutter
• Framework revision 2d2a1ff (3 weeks ago), 2019-09-06 18:39:49 -0700
• Engine revision b863200
• Dart version 2.5.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\Federico\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.38.1)
• VS Code at C:\Users\Federico\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.4.1


You can find the app here. It's a simple screen with the custom TextFormField and a FlatButton for the validation.

Thanks

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 27, 2019
@TahaTesser
Copy link
Member

Hi @belfed
Are you still experiencing this issue with latest flutter stable?
if yes, can you please provide your flutter doctor -v and flutter run --verbose?
Also, to better address the issue, would be helpful if you could post a minimal code sample to reproduce the problem
Thank you

@TahaTesser TahaTesser added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 15, 2020
@iapicca
Copy link
Contributor

iapicca commented Jun 3, 2020

Hi @belfed
with this code sample
the issue appear to be solved

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,
if you disagree please write in the comments
and I will reopen it.
Thank you

@iapicca iapicca closed this as completed Jun 3, 2020
@iapicca iapicca removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 3, 2020
@github-actions
Copy link

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 flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

No branches or pull requests

5 participants