书写时如何隐藏/移动图像

时间:2019-07-04 12:12:27

标签: flutter dart

我正在Flutter上书写表格,但是在书写时,textFields却看不到,因为键盘覆盖了它。因此,我想减小图像的大小,并在必要时移动以显示文本文件。

这是它的开始方式:

enter image description here

当我在密码字段上书写时,情况就是这样:

enter image description here

因此,我希望在编写页面时看到活动焦点文本字段。每个TextField都有一个TextController和一个FocusNode,但我不知道如何解决。

一个textField示例:

final emailField = TextFormField(
      controller: emailController,
      focusNode: emailFocusNode,
      keyboardType: TextInputType.emailAddress,
      onFieldSubmitted: (String value) {
        FocusScope.of(context).requestFocus(passwordFocusNode);
      },
      validator: (val) =>
          (!EmailValidator.validate(val)) ? 'Incorrect Email' : null,
      onSaved: (val) => _username = val,
      textInputAction: TextInputAction.next,
      style: style,
      decoration: InputDecoration(
          contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
          hintText: "Email",
          fillColor: Colors.white,
          filled: true,
          border:
              OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
    );

总结一下,我需要根据选择的TextField来显示它以及键盘没有覆盖它,来移动屏幕。

1 个答案:

答案 0 :(得分:0)

例如,尝试将代码包含在 SingleChildScrollView

import 'package:flutter/material.dart';

class S56887705 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final emailField = TextFormField(
      keyboardType: TextInputType.emailAddress,
      textInputAction: TextInputAction.next,
      decoration: InputDecoration(
          contentPadding: EdgeInsets.fromLTRB(20.0, 25.0, 20.0, 25.0),
          hintText: "Email",
          fillColor: Colors.white,
          filled: true,
          border:
              OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
    );

    return MaterialApp(
      home: SafeArea(
          child: Scaffold(
        body: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              emailField,
              SizedBox(
                height: 35,
              ),
              emailField,
              SizedBox(
                height: 35,
              ),
              emailField,
              SizedBox(
                height: 35,
              ),
              emailField,
              SizedBox(
                height: 35,
              ),
              emailField,
              SizedBox(
                height: 35,
              ),
              emailField,
              SizedBox(
                height: 35,
              ),
              emailField,
              SizedBox(
                height: 35,
              ),
              emailField,
              SizedBox(
                height: 35,
              ),
            ],
          ),
        ),
      )),
    );
  }
}