Flutter Row使用

1、解决平分宽度,并各自从左开始布局

                          Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            mainAxisSize: MainAxisSize.max,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            //元素与空白互相间隔
                            children: [
                              Expanded(
                                flex: 1,//设置权重
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  textDirection: TextDirection.ltr,
                                  children: [
                                    Text(
                                      "企业生产状态:",
                                      style: TextStyle(color: Colors.black26),
                                    ),
                                    Text(
                                      "正常",
                                      style: TextStyle(color: Colors.black87),
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                  flex: 1,//设置权重
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    mainAxisSize: MainAxisSize.max,
                                    children: [
                                      Text(
                                        "行业:",
                                        style: TextStyle(color: Colors.black26),
                                      ),
                                      Expanded(//解决Text文本过长超出屏幕错误
                                        child: Text(
                                          mList[index].industryClass,
                                          maxLines: 1,
                                          overflow: TextOverflow.ellipsis,
                                          style:
                                              TextStyle(color: Colors.black87),
                                        ),
                                      ),
                                    ],
                                  )),
                            ],
                          ),

2、解决Row中Text文本过长超出屏幕错误

Row(
   mainAxisAlignment: MainAxisAlignment.start,
   mainAxisSize: MainAxisSize.max,
   children: [
           Text("行业:",
                style: TextStyle(color: Colors.black26),
                ),
           Expanded(//解决Text文本过长超出屏幕错误
                    child: Text("很长很长的文本很长很长的文本一行装不下",
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style:TextStyle(color: Colors.black87),),
                    ),
             ],
    )

 

你可能感兴趣的:(Flutter,flutter)