flutter - Flutter:出现键盘时向上滚动屏幕
问题描述
我正在尝试构建一个登录屏幕,其中包含顶部的电话号码字段以及底部的图像和登录按钮,一旦我点击电话号码字段键盘升起但我的“登录按钮”隐藏在键盘后面,我已使用“SingleChildScrollView”,以便当键盘上升时页面变为可滚动但登录按钮不会出现在键盘顶部。
这是代码片段:
return Scaffold(
backgroundColor: white.color,
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
child: Text(
'Enter your mobile number',
style: TextStyle(
fontSize: headSize.fontSize,
fontWeight: FontWeight.w400,
color: black.color,
fontFamily: 'ProductSans',
),
),
),
Container(
height: screenHeight / 15,
child: Center(
child: SizedBox(
height: screenHeight / 6,
width: double.infinity,
child: RaisedButton(
color: indigo.color,
shape: borderRadius,
child: Text(
"Continue",
....
解决方案
尝试用screenHeight / 15 and screenHeight / 6
例如 100 替换并检查结果。
Container(
height: screenHeight / 15,
child: Center(
child: SizedBox(
height: screenHeight / 6,
width: double.infinity,
child: RaisedButton(
color: indigo.color,
shape: borderRadius,
child: Text(
"Continue",
顺便说一句,您将父级的高度设置为小于子级。我想知道为什么?:)
例如,如果 screenHeight = 100
100/15 = 6.6 父母
100/6 = 16.6 孩子
推荐阅读
- python - 如何在shell中更改diff的二进制文件?
- wordpress - Google Drive API 每天 10 亿次查询限制
- ruby-on-rails - Rails 动态创建模型并使用它
- javascript - JavaScript - 在类方法中动态设置类属性
- c++ - 从结构中提取数据?
- java - Java MariaDB 连接错误:用户 'root'@'localhost' 的访问被拒绝
- dc.js - d3.queue 没有给出输出
- java - 为什么Fragment中的click事件会回到最后一个活动而没有在Android中的setOnClickListener中给出任何此类指令?
- graphql - 为什么我无法通过 GraphiQl 自省查询列出所有查询?
- java - 依赖项位于 pom.xml 中时找不到工件