Home > Software design >  why the text inside the container does not show flutter
why the text inside the container does not show flutter

Time:05-10

hello i'm new in flutter so inside a column a container then a sized box then another container and finally a button . the problem is the container which have the color amber does not show despite print is worked but i don't see the container on my screen . i wanna display a text inside that container if the email invalid any help ! thanks in advise

             Container(
                height: MediaQuery.of(context).size.height * 0.08,
                margin: const EdgeInsets.symmetric(horizontal: 5),
                decoration: BoxDecoration(
                  color: const Color(0xFFEFEDED),
                  border: Border.all(color: Colors.transparent),
                  borderRadius: BorderRadius.circular(10),
                ),
                child: Padding(
                  padding: const EdgeInsets.only(left: 8.0),
                  child: TextFormField(
                    controller: emailController,
                    keyboardType: TextInputType.emailAddress,
                    decoration: const InputDecoration(
                      border: InputBorder.none,
                    ),
                  ),
                ),
              ),

              const SizedBox(
                height: 50,
              ),
              InkWell(
                  onTap: () {

                    if (isValidEmail) {
                      emailsList.add(emailController.text);
                      box.write('emails', emailsList);

                      Navigator.of(context).pop();
                    }
                    if (!isValidEmail) {

                    Row(

                        children: [
                          Container(
                            color: Colors.amber,

                          ),
                        ],
                      );
                      print("test");
                    }
                  },
                  child: CustomButton("Ajouter", buttonColor, Colors.white)),

CodePudding user response:

put a Row in Inkwell onTap? Row is not a function, you must return it in your build method.

CodePudding user response:

return type of if statement must be 'Widget' . use 'return' before Container widget.

CodePudding user response:

First of all, if you do not give any height or width to your container but only a color, it will never show. Why? Because it has no content meaning that the height and width by default are 0. So, I advise setting a height and width first.

Second, if you want to display a text if the field is not valid, you have something already existing. In your textField, you can give him an Inputdecoration and there you can access the parameters errorText. In order to have this working, you must use the formValidation with the widget Form and you kive him a key that is a formValidator.

Finally, if you do not want to use the errorText by default, you should put in the column something like this.

Column(
  children:[
    TextField(),
    if (isEmailInvalid)
      Text("This is the error Text")
  ]
)

With the "isEmailInvalid" which is a boolean.

I hope that all this information helps you. But if you have really a beginner, I advise to stick with the default setting of the TextField and take a look at the flutter documentation that is really interesting.

  • Related