【问题标题】:Card width match with parent : flutter卡片宽度与父级匹配:颤动
【发布时间】:2019-07-15 01:35:01
【问题描述】:

我是 Flutter 的新手,所以我想知道如何设置宽度以匹配父布局宽度

new Scaffold(
    body: new Container(
  decoration: new BoxDecoration(color: AppColors.hoBlue),
  child: Padding(
    padding: EdgeInsets.all(20.0),
    child: new Center(
        child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Stack(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                  child: Padding(
                    padding: EdgeInsets.all(20.0),
                    child: Card(
                      child: Padding(
                          padding: EdgeInsets.fromLTRB(20, 0.0, 20.0,20.0),
                          child: Column(
                            children: <Widget>[
                               Card(
                                    elevation: 10.0,
                                    child: Padding(
                                      padding: EdgeInsets.all(20.0),
                                      child:
                                      Text("Sign Up Here"),
                                    ),
                                  ),
                              TextField(
                                decoration: InputDecoration(
                                  labelText: "Email",
                                  hintText: "example@mail.com",
                                ),
                                autofocus: true,
                              ),
                              TextField(
                                decoration: InputDecoration(
                                  labelText: "Password",
                                ),
                                autofocus: true,
                              ),
                              SizedBox(
                                width: double.infinity,
                                // height: double.infinity,
                                child: new RaisedButton(
                                  color: AppColors.hoBlue,
                                  child: Text(
                                    "Sign In",
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontFamily: 'Raleway',
                                      fontSize: 22.0,
                                    ),
                                  ),
                                  onPressed: () => print('Sign In'),
                                ),
                              )
                            ],
                          )),
                    ),
                  ),
                ),
              ],
            )
          ],
        ),
      ],
    )),
  ),
));

Result From Code Above

我需要帮助才能与父母一起制作卡片叠 Result I want

我已经尝试使用堆栈,但结果卡父卡与第一张卡重叠。

我对 Expanded 标签了解一点,但是 Expanded expand view to both方向,我不知道该怎么做。如果您知道,请帮助我,提前致谢。

【问题讨论】:

    标签: dart flutter flutter-layout


    【解决方案1】:

    只需将卡片放入容器中

    Padding(
                padding: EdgeInsets.all(20),
                child: Container(
                  height: 50,
                  width: double.infinity,
                  child: Card(
                    child: Align(
                        alignment: Alignment.centerLeft,
                        child: Text("Edit Profile")),
                  ),
                ),
              )
    

    【讨论】:

      【解决方案2】:

      使用Material 小部件,其使用方式与卡片相同...并且始终采用与其父类相同的完整宽度和高度...

      【讨论】:

        【解决方案3】:

        如果您想调整或更改卡片视图然后只需将 Card 放入 Container 视图中,然后调整您的容器大小。 此链接将对您有所帮助:https://stackoverflow.com/a/50017126/7418129

        【讨论】:

          【解决方案4】:

          您不需要 Stack 来获得该视图 - 可以使用 ColumnMaterial 小部件来完成。

          return Scaffold(
                  body: new Container(
                decoration: new BoxDecoration(color: Colors.blue),
                child: new Center(
                    child: MergeSemantics(
                      child: Padding(
                        padding: const EdgeInsets.all(16.0),
                        child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                        Card(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.stretch,
                            children: <Widget>[
                              Material(
                                elevation: 24.0,
                                child: Padding(
                                  padding: const EdgeInsets.all(20.0),
                                  child: Text("Sign Up Here"),
                                ),
                              ),
                              Padding(
                                  padding: EdgeInsets.fromLTRB(20, 10.0, 20.0, 20.0),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.stretch,
                                    children: <Widget>[
                                      TextField(
                                        decoration: InputDecoration(
                                          labelText: "Email",
                                          hintText: "example@mail.com",
                                        ),
                                        autofocus: true,
                                      ),
                                      TextField(
                                        decoration: InputDecoration(
                                          labelText: "Password",
                                        ),
                                        autofocus: true,
                                      ),
                                      SizedBox(
                                        width: double.infinity,
                                        // height: double.infinity,
                                        child: new RaisedButton(
                                          color: Colors.blue,
                                          child: Text(
                                            "Sign In",
                                            style: TextStyle(
                                              color: Colors.white,
                                              fontFamily: 'Raleway',
                                              fontSize: 22.0,
                                            ),
                                          ),
                                          onPressed: () => print('Sign In'),
                                        ),
                                      )
                                    ],
                                  )),
                            ],
                          ),
                        ),
                  ],
                ),
                      ),
                    )),
              ));
          

          输出:

          【讨论】:

          • Link 到 Material 小部件。
          猜你喜欢
          • 2020-12-03
          • 1970-01-01
          • 1970-01-01
          • 2018-10-05
          • 1970-01-01
          • 2015-10-13
          • 1970-01-01
          • 1970-01-01
          • 2016-04-09
          相关资源
          最近更新 更多