【问题标题】:How to hide/move image while writting如何在写作时隐藏/移动图像
【发布时间】:2019-07-04 12:12:27
【问题描述】:

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

它是这样开始的:

当我在密码字段上写字时,它是这样的:

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

文本字段的一个示例:

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 来显示它并且它没有被键盘覆盖来移动屏幕。

【问题讨论】:

  • 你可以把它包装成一个ScrollerView。当您将 textfields 聚焦时,图像将 sccoll 到顶部
  • @user8773560 你能公开一个例子吗?
  • 您是否在此屏幕上使用Scaffold?此外,使用ListView 而不是Column 作为您的TextFileds 和图像,那么您应该没问题。在这里可以帮助您的是 Scaffold 中的属性,即 resizeToAvoidBottomInset,默认为 trueapi.flutter.dev/flutter/material/Scaffold/…
  • @JuanGomez 提供整个屏幕的代码,如果您仍然无法弄清楚,我们可以帮助您。

标签: flutter dart


【解决方案1】:

例如,尝试将您的代码包含在 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,
              ),
            ],
          ),
        ),
      )),
    );
  }
}

【讨论】:

  • 谢谢!我有一个 GestureDetector,但我忘记了 SingleChildScrollView
猜你喜欢
  • 2022-09-28
  • 2016-04-26
  • 1970-01-01
  • 2019-07-03
  • 2014-02-18
  • 1970-01-01
  • 2018-07-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多