Flutter:(TextFormField)打开键盘并开始打字时出现问题



当我打开键盘开始打字时,出现的问题是空间太大[1] :https://i.stack.imgur.com/Nk4l6.png[2] :https://i.stack.imgur.com/12jNe.png代码:

import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
class SignUpScreen extends StatelessWidget {
@override
var Email, Pass;
var txt;
GlobalKey<FormState> formstate = new GlobalKey<FormState>();

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
toolbarHeight: 0,
leading: Container(),
backgroundColor: Color(0xFF03045E),
),
body: Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFF03045E),Color(0xFF1F21D5),]
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: 45,
height: 45,
margin: EdgeInsets.only(top: 70,right: 35),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Color(0xff383989),
),
child: FlatButton(
onPressed: (){
Get.back();
},
child: Image(
image: AssetImage('assets/images/cancel-icon.png'),
color: Colors.white,
width: double.infinity,
),
),
),
],
),
Container(
margin: EdgeInsets.symmetric(horizontal: 35),
child: Column(
children: [
Container(
margin: EdgeInsets.only(bottom: 40),
child: Row(
children: [
Text('Createn Account',style: TextStyle(
color: Colors.white,
fontSize: 30
),),
],
),
),
Row(
children: [
Text('Create account and enjoy 7 days free trial',style: TextStyle(
color: Color(0xffB2B2DC),
fontSize: 15
),),
],
),
],
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
Expanded(flex: 1 , child: Container(),),
Expanded(
flex: 10,
child: TextFormField(
keyboardType: TextInputType.name,
cursorColor: Colors.white,
style: TextStyle(fontSize: 18, color: Colors.white),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white24,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
contentPadding: EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
hintText: 'Your first and last name?',
labelText: 'Full Name',
labelStyle: TextStyle(color:Colors.white60 , fontSize: 18),
hintStyle: TextStyle(color:Colors.white60 , fontSize: 18),
),
onSaved: (val) {
Email = val;
},
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter some text';
}
},
),
),
Expanded(flex: 1 , child: Container(),)
],
),
Row(
children: [
Expanded(flex: 1 , child: Container(),),
Expanded(
flex: 10,
child: TextFormField(
keyboardType: TextInputType.emailAddress,
cursorColor: Colors.white,
style: TextStyle(fontSize: 18, color: Colors.white),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white24,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
contentPadding: EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
labelText: 'Email',
labelStyle: TextStyle(color:Colors.white60 , fontSize: 18),
hintStyle: TextStyle(color:Colors.white60 , fontSize: 18),
),
onSaved: (val) {
Email = val;
},
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter some text';
}
},
),
),
Expanded(flex: 1 , child: Container(),)
],
),
Row(
children: [
Expanded(flex: 1 , child: Container(),),
Expanded(
flex: 10,
child: TextFormField(
keyboardType: TextInputType.visiblePassword,
cursorColor: Colors.white,
style: TextStyle(fontSize: 18, color: Colors.white),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white24,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
contentPadding: EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
labelText: 'password',
labelStyle: TextStyle(color:Colors.white60 , fontSize: 18),
hintStyle: TextStyle(color:Colors.white60 , fontSize: 18),
),
onSaved: (val) {
Email = val;
},
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter some text';
}
},
),
),
Expanded(flex: 1 , child: Container(),)
],
),
Row(
children: [
Expanded(flex: 1 , child: Container(),),
Expanded(
flex: 10,
child: TextFormField(
keyboardType: TextInputType.visiblePassword,
cursorColor: Colors.white,
style: TextStyle(fontSize: 18, color: Colors.white),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white24,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
contentPadding: EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
labelText: 're-password',
labelStyle: TextStyle(color:Colors.white60 , fontSize: 18),
hintStyle: TextStyle(color:Colors.white60 , fontSize: 18),
),
onSaved: (val) {
Email = val;
},
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter some text';
}
},
),
),
Expanded(flex: 1 , child: Container(),)
],
),
Container(
margin: EdgeInsets.only(bottom: 50,top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(flex: 1 , child: Container(),),
Expanded(
flex: 10,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)
),
color: Colors.white,
height: 70,
onPressed: (){},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Text('Sign up',textAlign:TextAlign.center,
style: TextStyle(
color: Color(0xff03045E),
fontSize: 18.0,
),),
),
],
),
),
),
Expanded(flex: 1 , child: Container(),),
],
),
),
],
),
),
],
),),
],
),
),
);
}
}

=============呈现库捕获到异常=====================================================布局过程中引发了以下断言:RenderFlex底部溢出了51个像素。

导致错误的相关小部件是:列列:file:///M:/Android%20PG/lockvpn0/lib/view/auth/sign-向上飞镖:87:26溢出的RenderFlex的方向为Axis.vertical。渲染中已使用黄色和黑色条纹图案标记溢出的RenderFlex边缘。这通常是因为内容对于RenderFlex来说太大。

考虑应用弹性因子(例如,使用扩展小部件(来强制RenderFlex的子级适应可用空间,而不是按其自然大小调整大小。这被认为是一种错误情况,因为它表明存在无法看到的内容。如果内容合法地大于可用空间,请考虑在将其放入flex之前使用ClipRect小部件对其进行剪裁,或者使用可滚动容器而不是flex,如ListView。

有问题的具体RenderFlex是:RenderFlex#d12d3 relayoutBoundary=up5 OVERFLOING…需要合成…parentData:偏移量=偏移量(0.0260.0(;flex=1;fit=FlexFit.tight(可以使用尺寸(…约束:BoxConstraints(0.0<=w<=441.4,h=38.89(…size:大小(411.4388.9(…方向:垂直…主轴对齐:空间均匀…mainAxisSize:max…crossSaxAlignment:center…垂直方向:向下◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤

您可以使用SingleChildScrollView包装您的列。这应该可以解决溢出问题。

如果在脚手架上将resizeToAvoidBottomInset设置为true,则列不会被压扁,但也无法看到TextFields。

最新更新