簡體   English   中英

TextFormField 在 TextFormField 中顯示錯誤 - Flutter

[英]TextFormField showing error inside the TextFormField- Flutter

如圖所示,錯誤消息會干擾 TextField。 我正在使用容器作為父小部件來制作一些 UI 內容,但發生了這種情況。 如果沒有驗證消息,它就可以工作,我希望 TextField 下方的錯誤消息不在里面,請幫忙。

在此處輸入圖片說明

如圖所示,錯誤消息會干擾 TextField。 我正在使用容器作為父小部件來制作一些 UI 內容,但發生了這種情況。 沒有驗證消息它工作正常。 我想要 TextField 下面的錯誤消息不在里面,請幫忙。

import 'package:flutter/material.dart';
import 'package:email_validator/email_validator.dart';

class RoundedTextField extends StatelessWidget {
  final String hintText;
  final IconData iconData;
  final Color hintcolor, iconcolor;
  final bool password;
  final TextEditingController tcontroller;
  final TextInputType tType;

  const RoundedTextField(
      {Key key,
      @required this.hintText,
      @required this.iconData,
      @required this.hintcolor,
      this.iconcolor,
      this.password,
      this.tcontroller,
      this.tType})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;

    return Container(
      margin: EdgeInsets.symmetric(vertical: 10),
      padding: EdgeInsets.symmetric(vertical: 5, horizontal: 20),
      width: size.width * 0.8,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(29),
        color: Color(0xFFa5b2fc),
      ),
      child: TextFormField(
        controller: tcontroller,
        obscureText: password,
        keyboardType: tType,
        validator: (String value) {
          bool isValid = EmailValidator.validate(value);
          if (!password) {
            if (!isValid) {
              return "Invalid Email Address";
            }
          }
        },
        decoration: InputDecoration(
          suffixIcon: password
              ? (Icon(
                  Icons.visibility,
                  color: iconcolor,
                ))
              : null,
          border: InputBorder.none,
          icon: Icon(
            iconData,
            color: iconcolor,
          ),
          hintText: hintText,
          hintStyle: TextStyle(color: hintcolor),
        ),
      ),
    );
  }
}

使用 TexformField 中的裝飾。 包括文本、邊框、形狀、顏色

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM