Android 如何使用列内单子滚动视图颤振
我在一个子滚动视图中有一列。当我使用键盘键入时,我需要使登录屏幕滚动,因为键盘隐藏了密码文本字段Android 如何使用列内单子滚动视图颤振,android,ios,google-chrome,flutter,Android,Ios,Google Chrome,Flutter,我在一个子滚动视图中有一列。当我使用键盘键入时,我需要使登录屏幕滚动,因为键盘隐藏了密码文本字段 class UserRegistration extends StatefulWidget { @override _UserRegistrationState createState() => _UserRegistrationState(); } class _UserRegistrationState extends State<UserRegistration>
class UserRegistration extends StatefulWidget {
@override
_UserRegistrationState createState() => _UserRegistrationState();
}
class _UserRegistrationState extends State<UserRegistration> {
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Color(0xFF6C62FF)
));
return SafeArea(
child: GestureDetector(
onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
child: Scaffold(
resizeToAvoidBottomInset: false,
resizeToAvoidBottomPadding: false,
backgroundColor: Color(0xFF6C62FF),
body: SingleChildScrollView(
padding: EdgeInsets.symmetric(horizontal: 30),
child: Column([![enter image description here][1]][1]
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(child: FittedBox(child: Text('Welcome', style: TextStyle(fontFamily: 'SourceSans', fontSize: 50, fontWeight: FontWeight.w600, color: Color(0xFFFFD700)),))),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Register', style: TextStyle(fontFamily: 'SourceSans', fontSize: 40, fontWeight: FontWeight.w600, color: Colors.white)),
SizedBox(height: 5,),
Text('Start from today', style: TextStyle(fontFamily: 'SourceSans', fontSize: 25, letterSpacing: 1.5,fontWeight: FontWeight.w600, color: Colors.white), overflow: TextOverflow.ellipsis,),
],
),
),
Form(
child: Column(
children: [
EditTextNormal(hintText: 'Email', iconData: Icons.email, textInputType: TextInputType.emailAddress, validate: false, errorText: 'Enter your email',),
SizedBox(height: 20,),
EditTextObscure(hintText: 'Password', iconData: Icons.lock, textInputType: TextInputType.text, validate: false, errorText: 'Enter your password',),
SizedBox(height: 50,),
Container(
height: 50,
width: 180,
child: FlatButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)
),
onPressed: () {},
color: Colors.white,
child: Text('Register', style: TextStyle(color: Color(0xFF6C62FF), fontSize: 20), overflow: TextOverflow.ellipsis,),
),
)
],
),
),
Center(
child: RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: 'Login', style: TextStyle(color: Color(0xFFFFD700), letterSpacing: 1, wordSpacing: 1.5))
],
text: 'Have an account? ',
style: TextStyle(fontSize: 18, fontFamily: 'SourceSans', fontWeight: FontWeight.bold, letterSpacing: 1, wordSpacing: 1.5)
),
),
),
],
),
),
),
),
);
}
}
类用户注册扩展StatefulWidget{
@凌驾
_UserRegistrationState createState()=>\u UserRegistrationState();
}
类_UserRegistrationState扩展状态{
@凌驾
小部件构建(构建上下文){
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor:Color(0xFF6C62FF)
));
返回安全区(
儿童:手势检测器(
onTap:()=>FocusScope.of(context).requestFocus(FocusNode()),
孩子:脚手架(
resizeToAvoidBottomInset:false,
resizeToAvoidBottomPadding:false,
背景颜色:颜色(0xFF6C62FF),
正文:SingleChildScrollView(
填充:边缘组。对称(水平:30),
子:列([![在此处输入图像描述][1][1]
mainAxisAlignment:mainAxisAlignment.space,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
居中(子项:FittedBox(子项:文本('Welcome',样式:TextStyle(fontFamily:'SourceSans',fontSize:50,fontWeight:fontWeight.w600,颜色:颜色(0xFFFFD700)),),
容器(
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
Text('Register',style:TextStyle(fontFamily:'SourceSans',fontSize:40,fontWeight:fontWeight.w600,颜色:Colors.white)),
尺寸箱(高度:5,),
Text(“从今天开始”,样式:TextStyle(fontFamily:'SourceSans',fontSize:25,字母间距:1.5,fontWeight:fontWeight.w600,颜色:Colors.white),溢出:TextOverflow.省略号,),
],
),
),
形式(
子:列(
儿童:[
EditTextNormal(hintText:“电子邮件”,iconData:Icons.Email,textInputType:textInputType.emailAddress,validate:false,errorText:“输入您的电子邮件”,),
尺寸箱(高度:20,),
EditTextUnderset(hintText:“密码”,iconData:Icons.lock,textInputType:textInputType.text,validate:false,errorText:“输入密码”,),
尺寸箱(高度:50,),
容器(
身高:50,
宽度:180,
孩子:扁平按钮(
splashColor:Colors.transparent,
highlightColor:Colors.transparent,
形状:圆形矩形边框(
边界半径:边界半径。圆形(8)
),
按下:(){},
颜色:颜色,白色,
子项:Text('Register',样式:TextStyle(颜色:color(0xFF6C62FF),fontSize:20),溢出:TextOverflow.省略号,),
),
)
],
),
),
居中(
孩子:RichText(
text:TextSpan(
儿童:[
TextSpan(文本:“登录”,样式:TextStyle(颜色:color(0xFFFFD700),字母间距:1,字间距:1.5))
],
文本:“有账户吗?”,
样式:TextStyle(fontSize:18,fontFamily:'SourceSans',fontWeight:fontWeight.bold,letterSpacing:1,wordSpacing:1.5)
),
),
),
],
),
),
),
),
);
}
}
这是我的代码,但在这里,当我在单个子滚动视图空间中使用一列时,它不起作用。请给我一个解决办法
我的输出:
预期输出:在
SingleChildScrollView
中添加容器,并根据键盘是否打开来指定其高度
添加依赖项:
dependencies:
keyboard_visibility: ^0.5.6
在initState()
中为回调初始化键盘侦听器
bool _isKeyBoardShown = false;
@protected
void initState() {
super.initState();
KeyboardVisibilityNotification().addNewListener(
onChange: (bool visible) {
setState(() {
_isKeyBoardShown = visible;
});
},
);
}
根据显示的IsKeyboard值决定是否在屏幕上增加额外高度
Container(
width: MediaQuery.of(context).size.width,
height: _isKeyBoardShown
? MediaQuery.of(context).size.height +
MediaQuery.of(context).size.height / 2
: MediaQuery.of(context).size.height,
child: Column(....)
)
注意:使用MediaQuery
确定附加高度不要使用硬编码值
在这里,我使用了
MediaQuery.of(context).size.height/2
在SingleChildScrollView
中添加容器,并根据键盘是否打开为其指定高度
添加依赖项:
dependencies:
keyboard_visibility: ^0.5.6
在initState()
中为回调初始化键盘侦听器
bool _isKeyBoardShown = false;
@protected
void initState() {
super.initState();
KeyboardVisibilityNotification().addNewListener(
onChange: (bool visible) {
setState(() {
_isKeyBoardShown = visible;
});
},
);
}
根据显示的IsKeyboard值决定是否在屏幕上增加额外高度
Container(
width: MediaQuery.of(context).size.width,
height: _isKeyBoardShown
? MediaQuery.of(context).size.height +
MediaQuery.of(context).size.height / 2
: MediaQuery.of(context).size.height,
child: Column(....)
)
注意:使用MediaQuery
确定附加高度不要使用硬编码值
这里我使用了MediaQuery.of(context).size.height/2
试试这个
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
minHeight: MediaQuery.of(context).size.height,
),
child: IntrinsicHeight(
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// CONTENT HERE
],
),
),
),
),
);
}
小部件构建(构建上下文){
返回脚手架(
正文:SingleChildScrollView(
物理学:NeverscrollableScroll物理学(),
子:约束框(
约束:BoxConstraints(
minWidth:MediaQuery.of(context).size.width,
minHeight:MediaQuery.of(context).size.height,
),
孩子:内在的(
子:列(
mainAxisSize:mainAxisSize.max,
儿童:[
//满足于此
],
),
),
),
),
);
}
试试这个
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
minHeight: MediaQuery.of(context).size.height,
),
child: IntrinsicHeight(
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// CONTENT HERE
],
),
),
),
),
);
}
小部件构建(构建上下文){
返回脚手架(
正文:SingleChildScrollView(
物理学:NeverscrollableScroll物理学(),
子:约束框(
约束:BoxConstraints(
minWidth:MediaQu