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

问题描述 投票:1回答:1

我需要在flutter中对齐多个文本对象。当我嵌套容器时,文本在屏幕上每个容器缩进一点。我想如果我为每个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


         )


       );



}
} 

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

dart flutter
1个回答
2
投票

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

这是完整的代码:

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

© www.soinside.com 2019 - 2024. All rights reserved.