我正在创建一个登录屏幕,我有这个背景图片,
问题是当用户单击 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 ],
),
),
);
我也尝试使用设备屏幕的 minHeight
定义 BoxConstraints
但它没有帮助,并且也使用了 Stack
但与不是运气。
这就是我所说的改变尺寸的意思: No Keyboard/With Keyboard
最佳答案
将您的 Scaffold 作为 Container 的子级并使其透明
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,
],
),
),
);
https://stackoverflow.com/questions/49498784/
相关文章:
mobile - Dart:流与 ValueNotifiers
flutter - 如何在 flutter 的文本小部件中显示图标?
dart - 如何使用 Flutter 在 Android 中显示 iOS/cupertino 警报
dart - 有没有办法在 Flutter 的多个 PageRoutes 中使用 Inherited
c# - 将 Flutter 前端与 Android 和 iOS 的 .NET Core 后端相结合
dart - CustomScrollView 中的 Flutter 固定按钮