代码之家  ›  专栏  ›  技术社区  ›  DomingoMG

颤振:具有固定高度的响应性设计

  •  0
  • DomingoMG  · 技术社区  · 7 年前

    我正在创建一个管理俱乐部的部门。

    我遇到的问题与设计有关。

    我试图指出它在水平面上有相同的垂直高度,但我仍然不明白为什么机器人不根据它们的大小比例进行调整。

    我已经想了4个多小时怎么做了,一直没能做到,希望有人能帮我。

    我的目标 :垂直侧的设计应与水平侧相同

    我给你看我的密码

    return Scaffold(
          key: _scaffoldKey,
          appBar: new AppBar(
            title: new Text("LINE UP"),
            centerTitle: true,
            backgroundColor: Colors.lightBlue[500],
          ),
          body: LayoutBuilder(
              builder: (context, constraints) {
                return new Container(
                    color: Colors.blue[800],
                    child: new Stack(
                        children: <Widget>[
                          new Positioned.fill(
                              child: new SingleChildScrollView(
                                  scrollDirection: Axis.vertical,
                                  child: new Column(
                                      children: <Widget>[
                                        new Container(
                                            decoration: new BoxDecoration(
                                              image: new DecorationImage(
                                                  image: new AssetImage(imgStadium),
                                                  fit: BoxFit.fitWidth
                                              ),
                                            ),
                                            height: 411.4,
                                            width: constraints.maxWidth,
                                            child: new Stack(
                                              children: <Widget>[
                                                // BOT1
                                                Positioned(
                                                    top: 120.0,
                                                    left: 168.0,
                                                    child: new GestureDetector(
                                                      child: new Column(
                                                        children: <Widget>[
                                                          new Container(
                                                            decoration: BoxDecoration(
                                                              image: new DecorationImage(
                                                                image: new AssetImage(
                                                                    imgPlayer1),
                                                                fit: BoxFit.fill,
                                                              ),
                                                            ),
                                                            height: 40.0,
                                                            width: 30.0,
                                                          ),
                                                          new Container(
                                                            width: 70.0,
                                                            decoration: BoxDecoration(
                                                              shape: BoxShape
                                                                  .rectangle,
                                                              color: Colors.black
                                                                  .withOpacity(0.5),
                                                            ),
                                                            child: new Text(
                                                              "${textPlayer1}",
                                                              style: new TextStyle(
                                                                  color: Colors
                                                                      .white,
                                                                  fontWeight: FontWeight
                                                                      .bold,
                                                                  fontSize: 12.0),
                                                              textAlign: TextAlign
                                                                  .center,),
                                                          )
                                                        ],
                                                      ),
                                                      onTap: () {
                                                        setState(() {
                                                          _showModalSheet(1);
                                                        });
                                                      },
                                                    )
                                                ),
                                                //BOT2
                                                Positioned(
                                                    top: topPositionPlayer2,
                                                    left: leftPositionPlayer2,
                                                    child: new GestureDetector(
                                                      child: new Column(
                                                        children: <Widget>[
                                                          new Container(
                                                            decoration: BoxDecoration(
                                                              image: new DecorationImage(
                                                                image: new AssetImage(
                                                                    imgPlayer2),
                                                                fit: BoxFit.fill,
                                                              ),
                                                            ),
                                                            height: 40.0,
                                                            width: 30.0,
                                                          ),
                                                          new Container(
                                                            width: 70.0,
                                                            decoration: BoxDecoration(
                                                              shape: BoxShape
                                                                  .rectangle,
                                                              color: Colors.black
                                                                  .withOpacity(0.5),
                                                            ),
                                                            child: new Text(
                                                              "${textPlayer2}",
                                                              style: new TextStyle(
                                                                  color: Colors
                                                                      .white,
                                                                  fontWeight: FontWeight
                                                                      .bold,
                                                                  fontSize: 12.0),
                                                              textAlign: TextAlign
                                                                  .center,),
                                                          )
                                                        ],
                                                      ),
                                                      onTap: () {
                                                        setState(() {
                                                          _showModalSheet(2);
                                                        });
                                                      },
                                                    )
                                                ),
                                                //BOT3
                                                Positioned(
                                                    top: topPositionPlayer3,
                                                    left: leftPositionPlayer3,
                                                    child: new GestureDetector(
                                                      child: new Column(
                                                        children: <Widget>[
                                                          new Container(
                                                            decoration: BoxDecoration(
                                                              image: new DecorationImage(
                                                                image: new AssetImage(
                                                                    imgPlayer3),
                                                                fit: BoxFit.fill,
                                                              ),
                                                            ),
                                                            height: 40.0,
                                                            width: 30.0,
                                                          ),
                                                          new Container(
                                                            width: 70.0,
                                                            decoration: BoxDecoration(
                                                              shape: BoxShape
                                                                  .rectangle,
                                                              color: Colors.black
                                                                  .withOpacity(0.5),
                                                            ),
                                                            child: new Text(
                                                              "${textPlayer3}",
                                                              style: new TextStyle(
                                                                  color: Colors
                                                                      .white,
                                                                  fontWeight: FontWeight
                                                                      .bold,
                                                                  fontSize: 12.0),
                                                              textAlign: TextAlign
                                                                  .center,),
                                                          )
                                                        ],
                                                      ),
                                                      onTap: () {
                                                        setState(() {
                                                          _showModalSheet(3);
                                                        });
                                                      },
                                                    )
                                                ),
                                              ],
                                            )
                                        )
                                      ]
                                  )
                              )
                          )
                        ]
                    )
                );
              }
          )
        );
    

    这里我给你看一些截图。

    垂直模式 -太好了。 enter image description here

    -我移动它和背景图像不适应。 enter image description here

    enter image description here

    2 回复  |  直到 7 年前
        1
  •  2
  •   Viren V Varasadiya    7 年前

    您提供了所有与垂直模式相关的高度和宽度,因此它们在水平视图中存在问题。 我想你得试试MediaQuery.of的(上下文)。尺寸.宽度获取宽度并设置您想要为填充设置的任何比例,或者使播放器图像居中,以便它在水平方向和垂直方向上都可以工作。

        2
  •  0
  •   Randal Schwartz    7 年前

    一般来说,当您缩进屏幕的一半时,我会将其重构为一个单独的方法,甚至是一个单独的小部件类。