Android 颤振:添加文本字段时出错
请检查我下面的代码Android 颤振:添加文本字段时出错,android,user-interface,dart,flutter,flutter-layout,Android,User Interface,Dart,Flutter,Flutter Layout,请检查我下面的代码 import 'package:flutter/material.dart'; class LoginPage extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return Scaffold( body: Container( color: Colors.black,
import 'package:flutter/material.dart';
class LoginPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: Container(
color: Colors.black,
child: Column(
children: <Widget>[_buildTitle(), _buildInputFields()],
),
),
);
}
Widget _buildTitle() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 100),
child: Column(
children: <Widget>[
Text(
"something.xyz",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 25,
),
// textAlign: TextAlign.center,
),
],
),
)
],
);
}
Widget _buildInputFields() {
return Row(
children: <Widget>[
Column(
children: <Widget>[
//Login Label
Container(
margin: EdgeInsets.only(
top: 30,
left: 20,
right: 20,
),
child: Text(
"Login with Email",
style: TextStyle(
color: Colors.white,
),
),
),
//Login Textfield
Container(
margin: EdgeInsets.only(
top: 5,
left: 20,
right: 20,
),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
)),
)],
)
],
);
}
}
我如何解决这个问题?另外,我如何修复文本字段
,使它们看起来像我的图像中的那些?想法如下:
您有一行,它将宽度设置为无限。
在里面,你有一个列,它将你的高度设置为无限
然后,您有一个容器,但尚未定义其宽度或高度,因此它从其父容器继承它们(无限)
文本小部件并不在意(我认为),因为在内部,它会自行调整大小。但TextField是这样的
您需要限制其宽度(或其父容器的宽度)
编辑:
简单的方法是为包含文本字段的容器设置width
属性。我在下面提供了一个例子。
还应查看行属性mainAxisAlignment
,以确定字段在行中的居中位置:
return Row(
mainAxisAlignment: MainAxisAlignment.center, // Center the child elements of the Row, along the Horizontal Axis
children: <Widget>[
Column(
children: <Widget>[
//Login Label
Container(
width: 200, // Set the width of the Container containing the Label so that it left aligns with your TextField below it
...
//Login Textfield
Container(
width: 200, // Set the width of the TextField container to restrict it from being infinite
返回行(
mainAxisAlignment:mainAxisAlignment.center,//使行的子元素沿水平轴居中
儿童:[
纵队(
儿童:[
//登录标签
容器(
宽度:200,//设置包含标签的容器的宽度,使其与下面的文本字段左对齐
...
//登录文本字段
容器(
宽度:200,//设置TextField容器的宽度以限制其为无限
谢谢。但我该怎么做呢?
return Row(
mainAxisAlignment: MainAxisAlignment.center, // Center the child elements of the Row, along the Horizontal Axis
children: <Widget>[
Column(
children: <Widget>[
//Login Label
Container(
width: 200, // Set the width of the Container containing the Label so that it left aligns with your TextField below it
...
//Login Textfield
Container(
width: 200, // Set the width of the TextField container to restrict it from being infinite