Widget build(BuildContext context) {
final logo = Image.asset("assets/images/logo.png", fit: BoxFit.fitWidth);
final emailField = TextField(
obscureText: false,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
labelText: "Email",
fillColor: Colors.white,
border:
OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(),
)
),
);
final passwordField = TextField(
obscureText: true,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
labelText: "Password",
border:
OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide()
)
),
);
final loginButton = Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(13.0),
color: Color.fromARGB(255, 40, 97, 143),
child: MaterialButton(
minWidth: MediaQuery.of(context).size.width,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {},
child: Text("Login",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold
)
),
),
);
final background = BoxDecoration(
image: DecorationImage(
image: ExactAssetImage("assets/images/background .png"),
fit: BoxFit.cover,
colorFilter: ColorFilter.mode(Colors.white.withOpacity(0.5), BlendMode.dstATop)
),
);
return Scaffold(
body: SingleChildScrollView(
child: Container(
decoration: background,
padding: EdgeInsets.all(25.0),
alignment: Alignment.topCenter,
child: Column(
children: <Widget>[
SizedBox(height: 85.0,),
logo,
SizedBox(height: 130.0,),
emailField,
SizedBox(height: 20.0,),
passwordField,
SizedBox(height: 20.0,),
loginButton
],
),
),
)
);
}
我不知道如何删除空格,任何人都可以向我解释我的代码有什么问题吗?
我添加了SingleChildScrollView',因为如果我不使用它,键盘会隐藏文本字段,但是如果没有SingleChildScrollView,我不会得到空格。
删除SingleChildScrollView可以工作,但是键盘有问题。
也许是另一种方式。
我被卡住了。
谢谢。
最佳答案
您将那些用作分隔符的SizedBox遇到几个问题。但是您可以删除该空白区域,从而为您的主Container添加一些高度。
像这样的东西:
Container(
height: MediaQuery.of(context).size.height, // add this line
decoration: background,
padding: EdgeInsets.all(25.0),
alignment: Alignment.topCenter,