gpt4 book ai didi

dart - 在 flutter 问题中对齐多个文本对象

转载 作者:IT王子 更新时间:2023-10-29 06:53:53 25 4
gpt4 key购买 nike

我需要在 flutter 中对齐多个文本对象。当我嵌套容器时,文本会在屏幕下方的每个容器中缩进一点。我想如果我为每个 Text 对象做一个容器,我可以单独控制每个对象的填充并将它们排到左边,但它会缩进每个对象。

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


)


);



}
}

我得到的结果是每个对象的缩进文本。它们都不对齐

最佳答案

基本上你有一些额外的位置不必要的组件,我也删除了其他不必要的东西。

完整代码如下:

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
),
],
),
);
}
}

关于dart - 在 flutter 问题中对齐多个文本对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54719180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com