我需要对齐多个文本对象。当我嵌套容器时,文本会在屏幕上缩进每个容器一点。我以为,如果我为每个Text对象都做一个Container,那么我可以单独控制每个对象的填充并将它们向左对齐,但是会向每个对象缩进。
class MemberProfile extends StatelessWidget {
@override
Widget build(BuildContext context){
return new Scaffold(
appBar: new LBAppBar().getAppBar(),
drawer: new LBDrawer().getDrawer(),
body: Container(
decoration: BoxDecoration(
gradient: new LinearGradient(
colors: [Color.fromRGBO(1,89,99, 1.0), Colors.grey],
begin: Alignment.bottomLeft,
end: Alignment.topRight
)
),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children:[
Row(
children: [
Container(
margin: EdgeInsets.only(left: 0.0,top: 0.0, bottom: 0.0, right:0.0),
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 0.0,top: 10.0, bottom: 10.0, right:0.0),
child: Text("Name : Sam Cromer", style: new TextStyle( color: Colors.white70, fontWeight: FontWeight.bold, fontSize: 19.0 )),
),
Container( margin: EdgeInsets.only(left: 0.0,top: 10.0, bottom: 10.0, right:0.0),
child: Text("Sex : Male", style: new TextStyle( color: Colors.white70, fontWeight: FontWeight.bold, fontSize: 19.0 )) ),
Container( margin: EdgeInsets.only(left: 0.0,top: 10.0, bottom: 10.0, right:0.0),
child: Text("Age : 42", style: new TextStyle( color: Colors.white70, fontWeight: FontWeight.bold, fontSize: 19.0 )) ),
Container( margin: EdgeInsets.only(left: 0.0,top: 10.0, bottom: 10.0, right:0.0),
child: Text("Status : Divorced", style: new TextStyle( color: Colors.white70, fontWeight: FontWeight.bold, fontSize: 19.0 )) ),
Container( margin: EdgeInsets.only(left: 0.0,top: 10.0, bottom: 10.0, right:0.0),
child: Text("Tramatic Event : ", style: new TextStyle( color: Colors.white70, fontWeight: FontWeight.bold, fontSize: 19.0 )) ),
Container( margin: EdgeInsets.only(left: 0.0,top: 10.0, bottom: 10.0, right:0.0),
child: Text("Motorcycle Accident July 2005, TBI", style: new TextStyle( color: Colors.white70, fontWeight: FontWeight.bold, fontSize: 19.0 )) ),
Container( margin: EdgeInsets.only(left: 0.0,top: 10.0, bottom: 10.0, right:0.0),
child: Text("Bio :", style: new TextStyle( color: Colors.white70, fontWeight: FontWeight.bold, fontSize: 19.0 )) ),
Container(
margin: EdgeInsets.only(left: 30.0,top: 100.0, bottom: 30.0, right:30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget> [
Container(
margin: EdgeInsets.all(20.0),
child:OutlineButton(
child: Text('Offer support'), textColor: Colors.white,
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
onPressed: (){
// Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new CheckInQ()));
}
)
)
]
)
)
],
),
),
]
),
],
),
//here
)
);
}
}
我得到的结果是每个对象的缩进文本。它们都不对齐
答案 0 :(得分:1)
基本上,您还有一些多余的位置不必要的组件,我还删除了其他不必要的东西。
这是完整的代码:
class MemberProfile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: LBAppBar().getAppBar(),
drawer: LBDrawer().getDrawer(),
body: ListView(
children: <Widget>[
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color.fromRGBO(1, 89, 99, 1.0), Colors.grey],
begin: Alignment.bottomLeft,
end: Alignment.topRight,
),
),
child: Container(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
child: Text("Name : Sam Cromer",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0)),
),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
child: Text("Sex : Male",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
child: Text("Age : 42",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
child: Text("Status : Divorced",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
child: Text("Tramatic Event : ",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
child: Text("Motorcycle Accident July 2005, TBI",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
child: Text("Bio :",
style: TextStyle(
color: Colors.white70,
fontWeight: FontWeight.bold,
fontSize: 19.0))),
Container(
margin: EdgeInsets.only(
left: 30.0, top: 100.0, bottom: 30.0, right: 30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
margin: EdgeInsets.all(20.0),
child: OutlineButton(
child: Text('Offer support'),
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
onPressed: () {
// Navigator.of(context).push( MaterialPageRoute(builder: (BuildContext context) => CheckInQ()));
},
),
)
],
),
)
],
),
),
//here
),
],
),
);
}
}