如何在颤动中改变按钮的位置

how to change the position of the button in the flutter

我有个问题,不难,但我解决不了。我有一个任务书程序。最上面是“任务”这个词,这个词根据需要在中间。但是还有一个按钮(添加)。问题是我不能把它放在离中心更近的地方,离“任务”这个词更近!如果有人能帮我把这个按钮移到中心到“任务”这个词的水平,我将不胜感激

我的代码:

Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,

                    children: <Widget>[
                      Expanded(
                          flex: 3,
                          child: Container(
                            margin: EdgeInsets.symmetric(horizontal: 40.0),
                            child: Text(("Tasks"),
                                style: TextStyle(fontSize: 70.0,
                                    color: Colors.black,
                                    fontWeight: FontWeight.bold)),
                          )
                      ),
                      Expanded(
                        child: FlatButton(
                          textColor: Colors.black,
                          color: Colors.white12,
                          child: Text('+',style: TextStyle(fontSize: 70.0,
                            color: Colors.black,
                          )),
                          onPressed:  () {
                            if (textController.text.isNotEmpty) {
                              WidgetList.add(
                                  new ListItem(textController.text, false));
                              setState(() {
                                valText = true;
                                textController.clear();

                              });
                            }
                            else
                            {
                              setState(() {
                                valText = false;
                              });
                            }
                          },
                          padding: EdgeInsets.fromLTRB(30.0, 10.0, 30, 10.0),
                          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
                        ),)


                    ],
                  ),

                ),

尽量不要使用 FlatButton 因为它已被弃用,当您使用图标创建按钮时,请改用 IconButton :

   Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center, // this is to center both
        children: <Widget>[
          const Text(
            "Tasks",
            style: TextStyle(
              fontSize: 24.0,
              color: Colors.black,
              fontWeight: FontWeight.bold,
            ),
          ),
          IconButton(
            color: Colors.black,
            iconSize: 28,
            constraints: const BoxConstraints(),
            padding: EdgeInsets.zero,
            icon: const Icon(Icons.add_outlined),
            onPressed: () {},
          )
        ],
      ),
    ),

好的,IconButton 中的限制,简而言之,它可以帮助您接近 TextIcon 并删除填充(但不是全部),aaaand 如果您添加 padding: EdgeInsets.zero,它实际上会将所有填充删除为零。尝试添加一些填充,以修复“更接近”