flutter - 颤振底部溢出 n 个像素,列结束对齐
问题描述
我试图在 Flutter 中显示一个简单的注册屏幕,但在bottom overflowed by n pixels
显示键盘时出现错误。
我的颤振小部件:
class SignUpScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(16),
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
children: [
Text(S
.of(context)
.signUpTitle,
style: AppTextTheme.kBigTitle),
Container(height: 16),
Text(
"Some text describing what happens when we do stuff with things and other stuff that probably won't fit in this layout and will give us the horrible error banner ath the bottom of the screen. There's scope for even more text depending on how I'm feeling this evening. It could be that I stop typing, it could be that I type more and more. It really depends on what ",
style: AppTextTheme.kParagraph),
Container(height: 24),
Text("Email address"),
TextField(
decoration: InputDecoration(
hintText: "Email address")),
Container(height: 8),
Text("Password"),
TextField(
decoration: InputDecoration(hintText: "Password")),
Container(height: 24),
MaterialButton(
onPressed: () {
// Do stuff
},
child: Text("Sign up"),
),
Container(height: 32),
FlatButton(
child: Column(
children: [
Text(
"Some other text",
style: AppTextTheme.kParagraphBold,
),
Text("Sign in instead",
style: AppTextTheme.kParagraphBold.copyWith(
decoration: TextDecoration.underline)),
],
),
onPressed: () {
Navigator.pushReplacementNamed(
context, RoutePaths.SIGN_IN);
},
)
]))));
}
}
我浏览了各种解决方案,但每个解决方案都有一个不受欢迎的权衡,要么会破坏设计,要么会产生不受欢迎的用户体验:
Column
将a包裹起来SingleChildScrollView
意味着Textfield
当键盘出现时 s 是隐藏的。- 设置在 s
resizeToAvoidBottomInset: false
上Scaffold
也会使TextField
s 隐藏在键盘后面。 Column
用 a替换ListView
意味着我无法设置 amainAxisAlignment
来MainAxisAlignment.end
获得我在内容底部对齐的屏幕截图中所追求的外观。
问题:
TextField
如何在内容与屏幕底部对齐的情况下实现我想要的 UI,并且在用户键入时仍然能够看到s 而不会出现像素溢出错误?
解决方案
Container
我刚刚通过使用和SingleChildScrollview
获取您的 UI包装列小部件来解决它。我希望这可以帮助你。
class SignUpScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(16),
child: SafeArea(
child: Container(
alignment: Alignment.bottomCenter,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.max,
children: [
Text(
'Sign Up',
// style: AppTextTheme.kBigTitle),
style: Theme.of(context).textTheme.headline,
),
Container(height: 16),
Text(
"Some text describing what happens when we do stuff with things and other stuff that probably won't fit in this layout and will give us the horrible error banner ath the bottom of the screen. There's scope for even more text depending on how I'm feeling this evening. It could be that I stop typing, it could be that I type more and more. It really depends on what ",
// style: AppTextTheme.kParagraph),
style: Theme.of(context).textTheme.body1,
),
Container(height: 24),
Text("Email address"),
TextField(
decoration: InputDecoration(hintText: "Email address"),
),
Container(height: 8),
Text("Password"),
TextField(
decoration: InputDecoration(hintText: "Password"),
),
Container(height: 24),
MaterialButton(
onPressed: () {
// Do stuff
},
child: Text("Sign up"),
),
Container(height: 32),
FlatButton(
child: Column(
children: [
Text(
"Already have an account ?",
// style: AppTextTheme.kParagraphBold,
style: Theme.of(context).textTheme.subtitle,
),
Text("Sign in",
// style: AppTextTheme.kParagraphBold
style: Theme.of(context)
.textTheme
.subtitle
.copyWith(
decoration: TextDecoration.underline)),
],
),
onPressed: () {
// Navigator.pushReplacementNamed(
// context, RoutePaths.SIGN_IN);
},
)
],
),
),
),
),
),
);
}
}
推荐阅读
- flutter - Flutter:错误:MissingPluginException(在通道 plugins.flutter.io/path_provider 上找不到方法 getTemporaryDirectory 的实现)
- r - 将数据拆分为区域组
- selenium - Specflow + selenium .NET Core 项目中缺少 Chromedriver
- angular - 如何从 10 条记录时获取的其余 api 显示角度材料表分页的数据总数
- python - 如何用透明背景和填充覆盖轮廓图像?
- flutter - 如何从 firebase userdataMap 获取用户凭据
- javascript - HREF有什么办法可以弹出这个吗?
- asp.net-core - 如何解决异常:当前线程与Dispatcher没有关联
- elasticsearch - Nginx 使用 ELK Stack + Kafka 记录管道
- docker - 如何在不退出终端的情况下退出一个命令行进程在没有其他方法的情况下运行?