Flutter 键盘隐藏的颤振文本字段,尝试多种解决方案但不起作用
聚焦文本字段时,键盘隐藏在文本字段上方。下面我附上了一个带有代码的截图。请指导我解决此问题 注册,飞镖 我正在尝试此解决方案:Flutter 键盘隐藏的颤振文本字段,尝试多种解决方案但不起作用,flutter,scroll,keyboard,textfield,Flutter,Scroll,Keyboard,Textfield,聚焦文本字段时,键盘隐藏在文本字段上方。下面我附上了一个带有代码的截图。请指导我解决此问题 注册,飞镖 我正在尝试此解决方案: 你能用SingleChildScrollView包装脚手架的主体,用ConstrainedBox包装容器吗 这是我得到的输出 键盘仍将位于文本字段的顶部,但通过使用SingleChildScrollView,屏幕将可滚动,以便您可以向下滚动并再次查看文本字段 这个解决方案对我有效 Scaffold( body: SingleChildScrollView(
你能用SingleChildScrollView包装脚手架的主体,用ConstrainedBox包装容器吗 这是我得到的输出 键盘仍将位于文本字段的顶部,但通过使用SingleChildScrollView,屏幕将可滚动,以便您可以向下滚动并再次查看文本字段 这个解决方案对我有效
Scaffold(
body: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
child: Container(
.
.
.
你能用SingleChildScrollView包装脚手架的主体,用ConstrainedBox包装容器吗 这是我得到的输出 键盘仍将位于文本字段的顶部,但通过使用SingleChildScrollView,屏幕将可滚动,以便您可以向下滚动并再次查看文本字段 这个解决方案对我有效
Scaffold(
body: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
child: Container(
.
.
.
您是否尝试过使用表单小部件?
将子项添加为SingleChildScrollView,它可以包含textformfield。是否尝试使用表单小部件?
将孩子添加为SingleChildScrollView,它可以有textformfield。嘿,我用扩展小部件解决了你的问题,用扩展小部件包装你的孩子内容。并删除一些我们不需要的额外列,尝试我下面的代码,让我知道它是否工作
import 'package:flutter/material.dart';
import 'package:yfobs/utilities/desc.dart';
class SignUpPage extends StatefulWidget {
static String tag = 'SignUpPage';
@override
_SignUpPageState createState() => _SignUpPageState();
}
class _SignUpPageState extends State<SignUpPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
resizeToAvoidBottomInset: true,
body: Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.topCenter, colors: [
Color(0xFF832685),
Color(0xFFC81379),
])),
child: Column(
children: <Widget>[
Expanded(
child: signUpCardUI(context),
),
],
)
),
);
}
}
Widget signUpCardUI(BuildContext context){
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 80,
),
Padding(
padding: const EdgeInsets.only(left:20.0),
child: Text(
"SignUp",
style: TextStyle(color: Colors.white, fontSize: 28),
),
),
SizedBox(
height: 30,
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0),
),
child: Padding(
padding:
EdgeInsets.only(bottom: 0, right: 20, left: 20),
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height / 1.5,
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.only(top: 60),
child: Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width / 1.2,
height: 40,
padding: EdgeInsets.only(
top: 0, left: 16, right: 16, bottom: 0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12, blurRadius: 5)
]),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
Icons.person,
color: Colors.grey,
),
hintText: 'Full Name',
),
),
),
Container(
width: MediaQuery.of(context).size.width / 1.2,
height: 40,
padding: EdgeInsets.only(
top: 0, left: 16, right: 16, bottom: 0),
margin: EdgeInsets.only(top: 16),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12, blurRadius: 5)
]),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
Icons.email,
color: Colors.grey,
),
hintText: 'Email',
),
),
),
Container(
width: MediaQuery.of(context).size.width / 1.2,
height: 40,
padding: EdgeInsets.only(
top: 0, left: 16, right: 16, bottom: 0),
margin: EdgeInsets.only(top: 16),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12, blurRadius: 5)
]),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
Icons.call,
color: Colors.grey,
),
hintText: 'Mobile Number',
),
),
),
Container(
width: MediaQuery.of(context).size.width / 1.2,
height: 40,
padding: EdgeInsets.only(
top: 0, left: 16, right: 16, bottom: 0),
margin: EdgeInsets.only(top: 16),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12, blurRadius: 5)
]),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
Icons.vpn_key,
color: Colors.grey,
),
hintText: 'Password',
),
obscureText: true,
),
),
Spacer(),
Container(
padding: EdgeInsets.all(10),
width: double.infinity,
child: RaisedButton(
elevation: 5.0,
padding: EdgeInsets.all(12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
color: Color(0xFFC81379),
child: Text(
'Sign Up'.toUpperCase(),
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
onPressed: () {
//Navigator.of(context).pushNamed('HomePage');
},
),
),
Align(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new FlatButton(
child: Padding(
padding: const EdgeInsets.only(
top: 0, right: 16, left: 16),
child: new Text(
Desc.alreadyUser,
style: TextStyle(color: Colors.grey),
),
),
onPressed: () {
Navigator.of(context)
.pushNamed('SignInPage');
},
color: Colors.white,
highlightColor: Colors.transparent,
),
]),
)
],
),
),
],
),
),
),
],
),
);
}
快乐编码:嘿,我用扩展小部件解决了你的问题,用扩展小部件包装你的子内容。并删除一些我们不需要的额外列,尝试我下面的代码,让我知道它是否工作
import 'package:flutter/material.dart';
import 'package:yfobs/utilities/desc.dart';
class SignUpPage extends StatefulWidget {
static String tag = 'SignUpPage';
@override
_SignUpPageState createState() => _SignUpPageState();
}
class _SignUpPageState extends State<SignUpPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
resizeToAvoidBottomInset: true,
body: Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.topCenter, colors: [
Color(0xFF832685),
Color(0xFFC81379),
])),
child: Column(
children: <Widget>[
Expanded(
child: signUpCardUI(context),
),
],
)
),
);
}
}
Widget signUpCardUI(BuildContext context){
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 80,
),
Padding(
padding: const EdgeInsets.only(left:20.0),
child: Text(
"SignUp",
style: TextStyle(color: Colors.white, fontSize: 28),
),
),
SizedBox(
height: 30,
),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0),
),
child: Padding(
padding:
EdgeInsets.only(bottom: 0, right: 20, left: 20),
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height / 1.5,
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.only(top: 60),
child: Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width / 1.2,
height: 40,
padding: EdgeInsets.only(
top: 0, left: 16, right: 16, bottom: 0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12, blurRadius: 5)
]),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
Icons.person,
color: Colors.grey,
),
hintText: 'Full Name',
),
),
),
Container(
width: MediaQuery.of(context).size.width / 1.2,
height: 40,
padding: EdgeInsets.only(
top: 0, left: 16, right: 16, bottom: 0),
margin: EdgeInsets.only(top: 16),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12, blurRadius: 5)
]),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
Icons.email,
color: Colors.grey,
),
hintText: 'Email',
),
),
),
Container(
width: MediaQuery.of(context).size.width / 1.2,
height: 40,
padding: EdgeInsets.only(
top: 0, left: 16, right: 16, bottom: 0),
margin: EdgeInsets.only(top: 16),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12, blurRadius: 5)
]),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
Icons.call,
color: Colors.grey,
),
hintText: 'Mobile Number',
),
),
),
Container(
width: MediaQuery.of(context).size.width / 1.2,
height: 40,
padding: EdgeInsets.only(
top: 0, left: 16, right: 16, bottom: 0),
margin: EdgeInsets.only(top: 16),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12, blurRadius: 5)
]),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
Icons.vpn_key,
color: Colors.grey,
),
hintText: 'Password',
),
obscureText: true,
),
),
Spacer(),
Container(
padding: EdgeInsets.all(10),
width: double.infinity,
child: RaisedButton(
elevation: 5.0,
padding: EdgeInsets.all(12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
color: Color(0xFFC81379),
child: Text(
'Sign Up'.toUpperCase(),
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
onPressed: () {
//Navigator.of(context).pushNamed('HomePage');
},
),
),
Align(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new FlatButton(
child: Padding(
padding: const EdgeInsets.only(
top: 0, right: 16, left: 16),
child: new Text(
Desc.alreadyUser,
style: TextStyle(color: Colors.grey),
),
),
onPressed: () {
Navigator.of(context)
.pushNamed('SignInPage');
},
color: Colors.white,
highlightColor: Colors.transparent,
),
]),
)
],
),
),
],
),
),
),
],
),
);
}
快乐编码:这个对我来说很有用
注册,飞镖
这个对我有用
注册,飞镖
尝试此解决方案:已尝试兄弟,我也添加了链接,在我的问题中尝试此解决方案:已尝试兄弟,我也添加了链接,在我的问题中我将尝试,不工作我将尝试,不工作脚手架正文:SingleChildScrollView子项:表单子项:容器。我将尝试这样做:正文>表单>SingleChildScrollView>列>文本表单字段。。。。。像这样,请在线查看表单小部件-上面的解决方案将起作用。Scaffold body:SingleChildScrollView child:form child:Container。我将尝试这样做:正文>表单>SingleChildScrollView>列>文本表单字段。。。。。像这样,请在线查看表单小部件-上述解决方案将起作用。兄弟我想要我的页面滚动,你的代码给我这个输出,你的代码减少我的空间,而不是滚动我的页面兄弟我想要我的页面滚动,你的代码给我这个输出,你的代码减少我的空间,而不是滚动我的页面