简体   繁体   English

Flutter TextFormField 提示 屏幕上出现错误文本

[英]Flutter TextFormField Hint Text is bugged on the screen

I'm trying to make a TextFormField with a centered hint text with a specific theme.我正在尝试制作一个带有特定主题的居中提示文本的 TextFormField。

Here's the result这是结果

在此处输入图像描述

I don't know why, but my hint text is totally bugged on the screen...我不知道为什么,但我的提示文本在屏幕上完全被窃听了......

Here are my codes:这是我的代码:

login_screen.dart login_screen.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';

class LoginScreen extends StatefulWidget {
  const LoginScreen({Key? key}) : super(key: key);

  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        SizedBox(
          height: 12.h,
        ),
        Text(
          "Flexmes",
          style: Theme.of(context).textTheme.bodyText2,
        ),
        SizedBox(
          height: 9.5.h,
        ),
        Container(
          width: 70.w,
          height: 3.h,
          decoration: BoxDecoration(
            border: Border(
              bottom: BorderSide(
                width: 0.13.w,
                color: Theme.of(context).splashColor,
              ),
            ),
          ),
          child: Padding(
            padding: EdgeInsets.fromLTRB(0.w, 0.h, 0.w, 0.6.h),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Icon(
                  Icons.email_outlined,
                  color: Theme.of(context).primaryColor,
                ),
                SizedBox(
                  width: 1.w,
                ),
                Expanded(
                  child: Material(
                    color: Colors.transparent,
                    child: TextFormField(
                      textAlign: TextAlign.center,
                      decoration: InputDecoration(
                        hintText :"Email",
                        hintStyle: Theme.of(context).textTheme.bodyText1,
                        border: InputBorder.none,
                      ),
                    ),
                  ),
                ),
                SizedBox(
                  width: 1.w,
                ),
                Icon(
                  Icons.visibility,
                  color: Theme.of(context).primaryColor,
                ),
              ],
            ),
          ),
        )
      ],
    );
  }
}

theme.dart主题.dart

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

enum AppTheme {
  authTheme,
}

final appThemeData = {
  AppTheme.authTheme: ThemeData(
    primaryColor: const Color.fromARGB(255, 219, 219, 219),
    splashColor: const Color.fromARGB(255, 164, 164, 164),
    textTheme: TextTheme(
      bodyText2: TextStyle(
        color: const Color.fromARGB(255, 164, 164, 164),
        fontSize: 40.sp,
        fontFamily: "Segoe-UI",
      ),
      bodyText1: TextStyle(
        color: const Color.fromARGB(255, 164, 164, 164),
        fontSize: 14.sp,
        fontFamily: "Segoe-UI",
      ),
    ),
  ),
};

I also want, when I write text in the field, it does start from the right and not from the center.我还希望,当我在字段中写文本时,它确实从右侧开始,而不是从中心开始。 I know it starts from the center because of the hint text, but is there another way to do it?由于提示文本,我知道它从中心开始,但是还有其他方法吗? :) :)

Big Thanks !非常感谢 !

Chris克里斯

Try below code hope its help to you.试试下面的代码希望它对你有帮助。 I tried it other way我尝试了其他方式

Refer TextFormField here 在此处参考TextFormField

Refer InputDecoration here 在此处参考InputDecoration

  TextFormField(
          textAlign: TextAlign.center,
          decoration: InputDecoration(
            hintText: 'Email',
            prefixIcon: Icon(
              Icons.email,
            ),
            suffixIcon: Icon(
              Icons.visibility,
            ),
          ),
        ),

Your result screen->您的结果屏幕-> 图片

The issue is coming from Container( height: 3.h because inner child is not having enough space, you need to have 48px for TextFiled height. Increase height of the container问题来自Container( height: 3.h ,因为内部子级没有足够的空间,您需要 48px 的TextFiled高度。增加容器的高度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM