我正在创建一个登录屏幕,我有这个背景图像, 问题是,当用户单击TextFields个中的一个时,键盘弹出,背景图像更改其大小以适应新的屏幕大小(不包括键盘).

我希望背景保持持久性和相同大小,我会使用BoxFit.none,但我担心这会损害应用程序的响应能力.

以下是代码:

new Container(
      decoration: new BoxDecoration(
          color: Colors.red,
          image: new DecorationImage(
              fit: BoxFit.cover,
              image: new AssetImage(
                  'assets/images/splash_screen/background.png'))),
      child: new Center(
        child: new ListView(
          physics: new PageScrollPhysics(),
          children: <Widget>[ //Login screen content ],
        ),
      ),
    );

我还try 在设备屏幕上用minHeight来定义BoxConstraints,但没有帮助,也用了Stack,但运气不佳.

以下是我所说的改变维度的意思: No Keyboard/With Keyboard

推荐答案

将脚手架作为容器的子级放置并使其透明

final emailField = TextFormField(
  decoration: InputDecoration(
    hintText: "Email",
  ),
);

return Container(
  decoration: BoxDecoration(
    image: DecorationImage(
      image: AssetImage('assets/bg.png'),
      fit: BoxFit.cover,
    ),
  ),
  child: Scaffold(
    backgroundColor: Colors.transparent,
    body: ListView(
      children: <Widget>[
        emailField,
      ],
    ),
  ),
);

Dart相关问答推荐

如何在将构造函数参数赋给最终变量和传递给超级构造函数之前操作它?

Flutter中TextFieldForm中的字母间距

禁用 ListView 滚动

Stack inside Stack in flutter

如何根据 Select 的选项卡更改样式?

如何使我的Flitter应用程序的导航抽屉(Navigation Drawer)透明?

如何通过 foreach 函数避免在 dart Map 中使用 await 键

Flutter:如何检测键盘按键?

如何使我的对话框可滚动?

如何在 Dart 中获取数字的长度?

如何循环遍历元素列表

如何判断switch/case中对象的类型?

如何在 Dart 中将字符串转换为 utf8?

在 Dart 中将 List 转换为字符串?

用 dart 解析日期

Dart:如何判断变量类型是否为字符串

什么是健全的编程语言?

安装 dart-sdk 后找不到 pub 命令

Dart 中 == 和 === 有什么区别?

何时在 Dart 中使用 part/part of 与 import/export?