Flutter Stack布局中为什么使用百分比布局不管用?

问题描述

Stack布局中使用FractionallySizedBox没有效果

相关代码

Widget build(BuildContext context) {
    return ConstrainedBox(
        // 容器
        constraints: BoxConstraints.expand(), // 最大宽高
        child: Stack(
          // 绝对定位
          children: <Widget>[
            SizedBox.expand(
                child: Image.asset('images/login_bg.png', fit: BoxFit.fill)),
            FractionallySizedBox(
              widthFactor: 80,
              heightFactor: 90,
              child: DecoratedBox(
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(5.0),
                      color: Color.fromRGBO(255, 255, 255, 0.9)),
                  child: MaterialButton(
                      child: Text('登录'),
                      onPressed: () {
                        Navigator.push(context,
                            MaterialPageRoute(builder: (context) {
                          return HomeWidget();
                        }));
                      })),
            )
          ],
        ));
  }

你期待的结果是什么?实际看到的错误信息又是什么?

中间的区域宽高按照百分比布局,实际得到的是中间区域铺满整个屏幕

阅读 4.2k
1 个回答

我知道怎么回事了,值应该是0.7,而不是70,值写错了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题