Flutter 颤振:-文本溢出

Flutter 颤振:-文本溢出,flutter,Flutter,我有下面的代码,我的文本在水平方向溢出。我尝试使用灵活和扩展的小部件,但没有成功 导入“包装:颤振/材料.省道”; 导入“widget/options/qty_widget.dart”; 导入“widget/options/option_widget.dart”; 导入“包:provider/provider.dart”; 导入“../session/data.dart”; 导入“../cart/cart.dart”; 类AddItemPage扩展StatefulWidget{ 最终字符串标题

我有下面的代码,我的文本在水平方向溢出。我尝试使用灵活和扩展的小部件,但没有成功

导入“包装:颤振/材料.省道”;
导入“widget/options/qty_widget.dart”;
导入“widget/options/option_widget.dart”;
导入“包:provider/provider.dart”;
导入“../session/data.dart”;
导入“../cart/cart.dart”;
类AddItemPage扩展StatefulWidget{
最终字符串标题='Add';
最终动态数据;
最终动态选项;
AddItemPage(this.data,this.itemOption);
@凌驾
State createState()=>addTempageState();
}
类AddItemPageState扩展了状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
背景颜色:颜色。琥珀色[800],
标题:文本(widget.title,
样式:TextStyle(颜色:Colors.amberAccent[800]),
),
主体:生成器(生成器:(BuildContext上下文){
List listWidget=[];
if(widget.data.containsKey('image')){
//String imagePath=“assets/images/menu/”+widget.data['image'];
字符串imagePath=“assets/images/lobster\u tray.png”;
listWidget.add(
划船(
mainAxisAlignment:mainAxisAlignment.start,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
容器(
子:Image.asset(
imagePath,
宽度:100,
)),
纵队(
mainAxisAlignment:mainAxisAlignment.start,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
文本(widget.data['dish'],
textAlign:textAlign.left,
样式:TextStyle(
fontWeight:fontWeight.w900,
尺寸:22,
颜色:颜色,黑色,
)),
文本(widget.data['description'],
textAlign:textAlign.left,
样式:TextStyle(
fontWeight:fontWeight.normal,
尺寸:16,
颜色:颜色,黑色,
)),
文本(“\$”+widget.data['price'],
textAlign:textAlign.left,
样式:TextStyle(
fontWeight:fontWeight.normal,
尺寸:16,
颜色:颜色,红色,
))
],
),
],
)
);
}
add(QtyWidget());
if(widget.data.containsKey('option')){
for(widget.data['option']中的字符串optionKey){
DynamicOptionData=widget.itemOption[optionKey];
添加(ItemOptionWidget(optionData));
}
}
添加(中间)(
子:容器(
填充:从LTRB(0,15,0,0)开始的边缘设置,
孩子:排(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
填充:常量边集。对称(垂直:16.0),
对齐:对齐.center,
孩子:升起按钮(
已按下:(){
Provider.of(上下文,侦听:false)
.addItemToCart(widget.data);
导航器。推(
上下文
材料路线(
生成器:(上下文)=>CartPage());
},
颜色:颜色。琥珀色[800],
子项:常量文本(“添加到订单”),
),
),
容器(
边距:从LTRB(10,0,0,0)开始的边距集,
填充:常量边集。对称(垂直:16.0),
对齐:对齐.center,
孩子:升起按钮(
onPressed:()异步{
pop(上下文,true);
},
颜色:颜色。灰色[200],
子项:常量文本(“取消”),
),
),
]),
),
));
返回容器(
填充:来自LTRB(15,15,15,15)的边缘设置,
孩子:表格(
子:ListView(
孩子们:listWidget,
),
),
);
}),
);
}
}

实际上您没有为行使用正确的权重,因此出现了此问题,我使用了
扩展的
并使用
MediaQuery
根据设备宽度管理宽度,请检查下面的解决方案

class HomeScreen extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _HomeScreen();
  }
}

class _HomeScreen extends State<HomeScreen> {
  var text =
      "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum";

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          title: Text("Home"),
        ),
        body: Container(
          height: MediaQuery.of(context).size.height * 0.18,
          child: Align(
              alignment: Alignment.topCenter,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                      width: MediaQuery.of(context).size.width * 0.3,
                      height: MediaQuery.of(context).size.height * 0.3,
                      decoration: BoxDecoration(
                        color: Colors.black,
                        borderRadius:
                        BorderRadius.all(Radius.elliptical(20.0, 20.0)),
                      )),
                  SizedBox(
                    width: 5.0,
                  ),
                  Container(
                      width: MediaQuery.of(context).size.width * 0.65,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Expanded(
                            flex:1,
                            child: Text("TITLE IS HERE",
                                textAlign: TextAlign.left,
                                style: TextStyle(
                                  fontWeight: FontWeight.w900,
                                  fontSize: 22,
                                  color: Colors.black,
                                )),
                          ),
                          Expanded(
                            flex:3,
                            child: Text(text,
                                textAlign: TextAlign.left,
                                maxLines: 3,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  fontWeight: FontWeight.normal,
                                  fontSize: 16,
                                  color: Colors.black,
                                )),
                          ),
                          Expanded(
                            flex:1,
                            child: Text('\$ 100',
                                textAlign: TextAlign.left,
                                style: TextStyle(
                                  fontWeight: FontWeight.normal,
                                  fontSize: 16,
                                  color: Colors.red,
                                )),
                          ),
                        ],
                      ))
                ],
              )),
        ));
  }
}
类主屏幕扩展StatefulWidget{
@凌驾
状态createState(){
//TODO:实现createState
返回主屏幕();
}
}
类_主屏幕扩展状态{
变量文本=
“Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,当一家不知名的印刷商在印刷和排版行业中大获全胜时,Lorem Ipsum一直是该行业的标准虚拟文本
class HomeScreen extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _HomeScreen();
  }
}

class _HomeScreen extends State<HomeScreen> {
  var text =
      "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum";

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          title: Text("Home"),
        ),
        body: Container(
          height: MediaQuery.of(context).size.height * 0.18,
          child: Align(
              alignment: Alignment.topCenter,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                      width: MediaQuery.of(context).size.width * 0.3,
                      height: MediaQuery.of(context).size.height * 0.3,
                      decoration: BoxDecoration(
                        color: Colors.black,
                        borderRadius:
                        BorderRadius.all(Radius.elliptical(20.0, 20.0)),
                      )),
                  SizedBox(
                    width: 5.0,
                  ),
                  Container(
                      width: MediaQuery.of(context).size.width * 0.65,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Expanded(
                            flex:1,
                            child: Text("TITLE IS HERE",
                                textAlign: TextAlign.left,
                                style: TextStyle(
                                  fontWeight: FontWeight.w900,
                                  fontSize: 22,
                                  color: Colors.black,
                                )),
                          ),
                          Expanded(
                            flex:3,
                            child: Text(text,
                                textAlign: TextAlign.left,
                                maxLines: 3,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  fontWeight: FontWeight.normal,
                                  fontSize: 16,
                                  color: Colors.black,
                                )),
                          ),
                          Expanded(
                            flex:1,
                            child: Text('\$ 100',
                                textAlign: TextAlign.left,
                                style: TextStyle(
                                  fontWeight: FontWeight.normal,
                                  fontSize: 16,
                                  color: Colors.red,
                                )),
                          ),
                        ],
                      ))
                ],
              )),
        ));
  }
}
body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              child: Image.asset('assets/placeholder.png', width: 100)
            ),
            Flexible(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text('dish', textAlign: TextAlign.left, style: TextStyle(
                      fontWeight: FontWeight.w900, fontSize: 22, color: Colors.black
                  ),),

                  Text('This is a long description of the dish presented in the picture and loved by customers.',
                      textAlign: TextAlign.left,
                      style: TextStyle(
                        fontWeight: FontWeight.normal,
                        fontSize: 16,
                        color: Colors.black,
                      )),
                  Text('\$' + 'price',
                      textAlign: TextAlign.left,
                      style: TextStyle(
                        fontWeight: FontWeight.normal,
                        fontSize: 16,
                        color: Colors.red,
                      ))
                ],
              )
            )

          ],
        )
      )