颤振和容器

约翰·高特

有人可以向我解释为什么,即使我设置了根容器的大小,该容器仍然全屏显示,而完全忽略了with和height设置:

  Widget build(BuildContext context) {
    return new Container( // grey box
      child: new Stack(
        textDirection: TextDirection.ltr,
        children: [
          new Positioned( // red box
            child:  new Container(
              child: new Text(
                "Lorem ipsum",
                textDirection: TextDirection.ltr,
              ),
              decoration: new BoxDecoration(
                color: Colors.red[400],
              ),
              padding: new EdgeInsets.all(16.0),
            ),
            left: 24.0,
            top: 24.0,
          ),
        ],

      ), 
      width: 300.0,
      height: 200.0,
      color: Colors.grey[300],
    );
  }
阿齐扎

如果您直接显示此窗口小部件而没有任何父窗口小部件,则不是在告诉Flutter应该在层次结构中的容器上方/外部呈现哪个视图?

例如,尝试为Scaffold父母添加一个Container,这样就可以解决您的问题

return new Scaffold(

        body: new Container(
          width: 300.0,
          height: 200.0,
    ........

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章