flutter两个container之间出现分隔线

当布局上有两个同色container时


class MyPage extends StatefulWidget {
  MyPage({Key? key}) : super(key: key);

  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            body: Center(
      child: TextButton(
          onPressed: () {
            showDialog(
                context: context,
                builder: (context) {
                  return _renderDialog();
                });
          },
          child: Text('test')),
    )));
  }

  _renderDialog() {
    return Container(
      alignment: Alignment.center,
      child: Container(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              width: 300,
              height: 300,
              decoration: BoxDecoration(
                color: Colors.white,
              ),
            ),
            Container(
              width: 300,
              height: 99,
              decoration: BoxDecoration(
                color: Colors.white,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

在这里插入图片描述可以看到两个container之间有一条奇怪的分隔线。
原因是flutter的绘制引擎无法正确对其物理像素,出现了间隙 ,漏出了背景色,而且不知道为什么官方一直都没有修复这个严重的bug。
参考issue

解决方法:为两个container设置宽度为0,颜色为背景色的边框

return Container(
      alignment: Alignment.center,
      child: Container(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              width: 300,
              height: 300,
              decoration: BoxDecoration(
                color: Colors.white,
                  //边框
                 border: Border.all(width: 0, color: Colors.white)
              ),
            ),
            Container(
              width: 300,
              height: 99,
              decoration: BoxDecoration(
                color: Colors.white,
                //边框
                border: Border.all(width: 0, color: Colors.white)
              ),
            ),
          ],
        ),
      ),
    );
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值