如何在Flutter布局中创建可编辑的输入字段?

发布于 2025-02-13 05:10:08 字数 2436 浏览 0 评论 0原文

我正在用flutter构建一个登录屏幕,并希望用字段替换下划线(“ ___________”),用户可以输入其电子邮件和密码。这是一个视觉表示:

预期的结果:

”在此处输入图像描述”

当前代码:

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

  @override
  State<LogInEnterEmailPassword> createState() => _LogInEnterEmailPasswordState();
}

class _LogInEnterEmailPasswordState extends State<LogInEnterEmailPassword> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xffF6F6F6),
      body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text("Enter email",
            style: TextStyle(
              fontSize: 20,
              fontStyle: FontStyle.normal,
              fontWeight:  FontWeight.normal,
              color: Color(0xff3B3B3B),
            ),),
              SizedBox(height: 20,),
              Text("______________________________",
                style: TextStyle(
                  fontSize: 20,
                  fontStyle: FontStyle.normal,
                  fontWeight:  FontWeight.normal,
                  color: Color(0xffD7D7D7),
                  
                ),),

              SizedBox(height: 110,),
              Text("Enter password",
                style: TextStyle(
                  fontSize: 20,
                  fontStyle: FontStyle.normal,
                  fontWeight:  FontWeight.normal,
                  color: Color(0xff3B3B3B),

                ),),
              SizedBox(height: 25,),
              Text("______________________________",
                style: TextStyle(
                  fontSize: 20,
                  fontStyle: FontStyle.normal,
                  fontWeight:  FontWeight.normal,
                  color: Color(0xffD7D7D7),

                ),),
              SizedBox(height: 110,),
              Icon(Icons.arrow_forward,
              size: 40,
                color: Color(0xff7E7E7E),)
            ],

          ),

      )
    );
  }
}

其他注释:

  • 我目前专注于前端设计。
  • 我正在考虑稍后的后端node.js。

I'm building a login screen in Flutter and want to replace the underscores ("___________") with fields where users can enter their email and password. Here's a visual representation:

Desired Outcome:

enter image description here

Current Code:

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

  @override
  State<LogInEnterEmailPassword> createState() => _LogInEnterEmailPasswordState();
}

class _LogInEnterEmailPasswordState extends State<LogInEnterEmailPassword> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xffF6F6F6),
      body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text("Enter email",
            style: TextStyle(
              fontSize: 20,
              fontStyle: FontStyle.normal,
              fontWeight:  FontWeight.normal,
              color: Color(0xff3B3B3B),
            ),),
              SizedBox(height: 20,),
              Text("______________________________",
                style: TextStyle(
                  fontSize: 20,
                  fontStyle: FontStyle.normal,
                  fontWeight:  FontWeight.normal,
                  color: Color(0xffD7D7D7),
                  
                ),),

              SizedBox(height: 110,),
              Text("Enter password",
                style: TextStyle(
                  fontSize: 20,
                  fontStyle: FontStyle.normal,
                  fontWeight:  FontWeight.normal,
                  color: Color(0xff3B3B3B),

                ),),
              SizedBox(height: 25,),
              Text("______________________________",
                style: TextStyle(
                  fontSize: 20,
                  fontStyle: FontStyle.normal,
                  fontWeight:  FontWeight.normal,
                  color: Color(0xffD7D7D7),

                ),),
              SizedBox(height: 110,),
              Icon(Icons.arrow_forward,
              size: 40,
                color: Color(0xff7E7E7E),)
            ],

          ),

      )
    );
  }
}

Additional Notes:

  • I'm currently focused on the frontend design.
  • I'm considering Node.js for the backend later.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言 2025-02-20 05:10:08

您的大小尺寸大小(高度:110)之间的小部件之间。这就是为什么要获得较大空间的原因,可以降低高度值,并使用高度播放:x值。

还使用crossaxisalignment:crossaxisalignment.start,column()

更新:更新:进行用户输入,使用textfield

class _LogInEnterEmailPasswordState extends State<LogInEnterEmailPassword> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF6F6F6),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: const [
            TextField(
              decoration: InputDecoration(
                hintText: "email",
                border: OutlineInputBorder(),
              ),
              style: TextStyle(
                fontSize: 20,
                fontStyle: FontStyle.normal,
                fontWeight: FontWeight.normal,
                color: Color(0xff3B3B3B),
              ),
            ),
            SizedBox(
              height: 10,
            ),
            TextField(
              decoration: InputDecoration(
                hintText: "Enter password",
                border: OutlineInputBorder(),
              ),
              style: TextStyle(
                fontSize: 20,
                fontStyle: FontStyle.normal,
                fontWeight: FontWeight.normal,
                color: Color(0xff3B3B3B),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

还有其他装饰可以像utlineInputborder一样使用。

您可以查看有关

  • 的 更多信息a href =“ https://api.flutter.dev/flutter/material/textfield-class.html” rel =“ nofollow noreferrer”> textfield

You are having large-sized of SizedBox(height:110) between widgets. that's why you are getting large spaces, you can reduce the height value, and play with the height:x value.

Also use crossAxisAlignment: CrossAxisAlignment.start, on the Column()

Update: to take user input, use TextField

class _LogInEnterEmailPasswordState extends State<LogInEnterEmailPassword> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF6F6F6),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: const [
            TextField(
              decoration: InputDecoration(
                hintText: "email",
                border: OutlineInputBorder(),
              ),
              style: TextStyle(
                fontSize: 20,
                fontStyle: FontStyle.normal,
                fontWeight: FontWeight.normal,
                color: Color(0xff3B3B3B),
              ),
            ),
            SizedBox(
              height: 10,
            ),
            TextField(
              decoration: InputDecoration(
                hintText: "Enter password",
                border: OutlineInputBorder(),
              ),
              style: TextStyle(
                fontSize: 20,
                fontStyle: FontStyle.normal,
                fontWeight: FontWeight.normal,
                color: Color(0xff3B3B3B),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

There are others decoration can be used like OutlineInputBorder.

You can check more about

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文