【问题标题】:Fit a column in expanded or container widget in Flutter在 Flutter 中的扩展或容器小部件中放置一列
【发布时间】:2020-10-04 14:32:37
【问题描述】:

我在我的 profilePage 中使用了 innerDrawer。我在脚手架上放了一列,并在里面添加了小部件。其中一个小部件是 SignedContracts,这个小部件有一个 Expanded 小部件,里面有一列。我想在扩展或容器小部件(如第二张图片)中填充或填充此列。我尝试了很多东西,但没有找到任何解决方案。

注意:第一张图片中的红色边框可以看到容器的边框。

我做了这个:

但我想要这样:

脚手架部分:

scaffold: Scaffold(
    body: Container(
      child: Column(
        children: [
          SizedBox(
            height: 20,
          ),
          Stack(
            children: [
              Container(
                decoration: BoxDecoration(
                  border: Border.all(color: Colors.red, width: 2),
                ),
                child: Image.network(
                  "${firestoreDB.user.photoURL}",
                  width: 500,
                  height: 250,
                  fit: BoxFit.fill,
                ),
              ),
              Positioned(
                child: IconButton(
                  icon: Icon(Icons.menu),
                  onPressed: () {
                    _toggle();
                  },
                ),
              ),
              Positioned(
                child: Text(
                  "${_user.name}",
                  style: TextStyle(color: Colors.white, fontSize: 20.0),
                ),
                bottom: 50,
                left: 50,
              ),
              Positioned(
                child: Text(
                  "${_user.desc}",
                  style: TextStyle(color: Colors.white, fontSize: 15.0),
                ),
                bottom: 30,
                left: 50,
              ),
            ],
          ),
          MiddleCounts(lastWeekListen, lastWeekStream,sL),
          Row(),
          SignedContracts(),
        ],
      ),
    ),
  ),

SignedContracts 小部件:

class SignedContracts extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        decoration:
            BoxDecoration(border: Border.all(color: Colors.red, width: 2)),
        alignment: Alignment.centerLeft,
        //height: 500,
        padding: EdgeInsets.all(30),
        //color: Colors.black,
        child: Container(
          decoration:
              BoxDecoration(border: Border.all(color: Colors.red, width: 2)),
          child: Column(
            //crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            children: [
              Text(
                "Signed Contracts",
                style: TextStyle(color: Colors.white, fontSize: 30.0),
              ),
              SizedBox(
                height: 20,
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Text(
                    "Multiple Rights Agreement",
                    style: TextStyle(color: Colors.grey),
                  ),
                  Text(
                    "Sound Recording Licence",
                    style: TextStyle(color: Colors.grey),
                  ),
                  Text(
                    "Merchandising Agreement",
                    style: TextStyle(color: Colors.grey),
                  ),
                  Text(
                    "Synchronisation Licence",
                    style: TextStyle(color: Colors.grey),
                  ),
                  Text(
                    "Artist Development Agreement",
                    style: TextStyle(color: Colors.grey),
                  ),
                  Text(
                    "Management Agreement",
                    style: TextStyle(color: Colors.grey),
                  ),
                ],
              ),
              FlatButton(
                onPressed: () {},
                child: Text(
                  "Manage Contracts",
                  style: TextStyle(color: Colors.white),
                ),
                color: Colors.red,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您可以使用 Expanded 小部件将您的第二个 Column 包装在 SignedContracts 类中,如下面的代码:

    class SignedContracts extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Expanded(
          child: Container(
            decoration:
                BoxDecoration(border: Border.all(color: Colors.red, width: 2)),
            alignment: Alignment.centerLeft,
            //height: 500,
            padding: EdgeInsets.all(30),
            //color: Colors.black,
            child: Container(
              decoration:
                  BoxDecoration(border: Border.all(color: Colors.red, width: 2)),
              child: Column(
                //crossAxisAlignment: CrossAxisAlignment.stretch,
                mainAxisAlignment: MainAxisAlignment.center,
                // mainAxisSize: MainAxisSize.max,
                children: [
                  Text(
                    "Signed Contracts",
                    style: TextStyle(color: Colors.white, fontSize: 30.0),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Expanded(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        Text(
                          "Multiple Rights Agreement",
                          style: TextStyle(color: Colors.grey),
                        ),
                        Text(
                          "Sound Recording Licence",
                          style: TextStyle(color: Colors.grey),
                        ),
                        Text(
                          "Merchandising Agreement",
                          style: TextStyle(color: Colors.grey),
                        ),
                        Text(
                          "Synchronisation Licence",
                          style: TextStyle(color: Colors.grey),
                        ),
                        Text(
                          "Artist Development Agreement",
                          style: TextStyle(color: Colors.grey),
                        ),
                        Text(
                          "Management Agreement",
                          style: TextStyle(color: Colors.grey),
                        ),
                      ],
                    ),
                  ),
                  FlatButton(
                    onPressed: () {},
                    child: Text(
                      "Manage Contracts",
                      style: TextStyle(color: Colors.white),
                    ),
                    color: Colors.red,
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2020-05-24
      • 2020-10-20
      • 1970-01-01
      • 2020-10-10
      • 2019-01-16
      • 2019-02-11
      相关资源
      最近更新 更多