繁体   English   中英

如何修复 flutter 中的溢出

[英]How to fix overflow in flutter

这是我的应用

在此处输入图像描述

如您所见,它运行良好,我将其安装在手机上,它也运行良好。 我把这个发给我的朋友,在他的手机里显示是这样的

在此处输入图像描述

我和他的手机是同一部手机,实际上是同一部手机,但是在他和其他任何手机中都显示此溢出,我的和此模拟器没有问题,我该如何解决溢出问题

这是代码:这是我的代码:```

https://pastebin.com/8BGnKTtj

没有您的代码,我无法更正当前代码。 但是,如果您需要无论屏幕大小如何都能工作的响应式 UI,我建议您根据需要使用带有扩展小部件的行、列。

例如,如果您需要在一行中有 2 个项目,每个项目占用相同的空间,您可以使用,

Row (
children: [
    Expanded (
      flex:1
      child: YourWidget()
    ),
    Expanded (
      flex:1
      child: YourWidget()
    )
  ]
)

请记住沿列或行的主轴删除硬编码的大小属性。

列也是如此。

如果您需要每个都有不同的大小,您可以使用扩展小部件的 flex 属性。 例如,一个项目有 1/3 的宽度,另一个有 2/3,您可以将 1 和 2 作为 flex 值。

flutter 团队的更多解释:已扩展

->使用此代码

 Widget build(BuildContext context) {
    double h =  MediaQuery.of(context).size.height;
    double w =  MediaQuery.of(context).size.width;
    return Scaffold(

      appBar: getAppBar(context, "Back", "", []),
      body: SafeArea(
        top: true,
        bottom: true,
        child: Column(
          children: [


            Expanded(
              child: ListView.builder(
                shrinkWrap: true,
                  physics: BouncingScrollPhysics(),
                  itemCount: 15,
                  itemBuilder: (context,v){
                return
                     Container(
                       padding: EdgeInsets.only(left: 15.0,right: 15.0),
                       child: Column(
                         children: [
                           Row(
                             mainAxisAlignment: MainAxisAlignment.spaceBetween,
                             children: [
                               Container(
                                 height: h*0.2,
                                 width: w*0.4,
                                 decoration: BoxDecoration(
                                   color: Colors.red,
                                   borderRadius: BorderRadius.circular(25.0)
                                 ),
                                
                               ),
                               Container(
                                 height: h*0.2,
                                 width: w*0.4,
                                 decoration: BoxDecoration(
                                     color: Colors.black38,
                                     borderRadius: BorderRadius.circular(25.0)
                                 ),
                               ),

                             ],
                           ),
                           SizedBox(height: 15.0,),
                           Divider(

                             color: Colors.black,
                           ),
                           SizedBox(height: 15.0,),
                         ],
                       ),
                     );
              }),
            )

            

          ],
        ),
      ),
    );
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM