flutter - 无法将 textField 添加到脚手架

标签 flutter dart

我对 Flutter 还很陌生(大约一个星期)。我正在尝试在 ListView 上方添加一个搜索字段。听起来很简单。但是我得到一个对我来说没有意义的错误(即使在大量谷歌搜索和阅读文档之后)。我理解这个错误,只是不知道为什么会这样。

return Scaffold(
        body :
        Padding(
          padding: EdgeInsets.all(3.0),
          child:
          TextField(
            controller: searchController,
            decoration: InputDecoration(
                icon: Icon(Icons.search),
                hintText: "search text",
                border: OutlineInputBorder()
            ), //decoration
          ), //textfield
        ), // padding
        ListView.builder(
          itemCount : contactsModel.entityList.length,
          itemBuilder : (BuildContext inBuildContext, int inIndex) {
            Contact contact = contactsModel.entityList[inIndex];
            return Column(
              children : [
                Slidable(
                  delegate : SlidableDrawerDelegate(),
                  actionExtentRatio : .25,
                  child : ListTile(
                    title : Text("${contact.password}"),
                    subtitle : contact.pwordHint == null ? null : Text("${contact.pwordHint} - ${contact.notes}"),
                    // Edit existing contact.
                    onTap : () async {
                      contactsModel.entityBeingEdited = await ContactsDBWorker.db.get(contact.id);
                      contactsModel.setStackIndex(1);
                    }
                  ),
                  secondaryActions : [
                    IconSlideAction(
                      caption : "Delete",
                      color : Colors.red,
                      icon : Icons.delete,
                      onTap : () => _deleteContact(inContext, contact)
                    )
                  ]
                ),
                Divider()
              ]
            ); /* End Column. */
          } /* End itemBuilder. */
        ), /* End ListView.builder. */
          floatingActionButton : FloatingActionButton(
            child : Icon(Icons.add, color : Colors.white),
            onPressed : () async {
              contactsModel.entityBeingEdited = Contact();
              contactsModel.setStackIndex(1);
            }
          ),
      ); /* End Scaffold. */

我得到的错误是:

error: Too many positional arguments: 0 expected, but 1 found. (extra_positional_arguments_could_be_named at SCAFFOLD LINE
error: Positional arguments must occur before named arguments. (positional_after_named_argument at LISTVIEW.BUILDER LINE

如果我删除“BODY :”之后的 PADDING() 部分,则没有错误。

我不确定为什么 Listview 与 Padding 不同。我想我遗漏了一个或多个会使答案显而易见的基本概念。任何指导将不胜感激。

最佳答案

那是因为你正在使用

Scaffold(
  body: Widget1(),
        Widget2(),
  ...
)

这里 Widget1 是你的 PaddingWidget2ListView.builder

这不是正确的方法。您可以根据需要将 Widget1Widget2 包装在 StackColumn 中,如下所示:

Scaffold(
  body: Column(
    children: <Widget>[
      Widget1(),
      Widget2(),
    ],
  ),
)

关于flutter - 无法将 textField 添加到脚手架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57610278/

相关文章:

android - 安装location 2.3.5包时Flutter编译报错

flutter - Flutter 中的高效 Canvas 渲染

android - 为什么我的调用堆栈说我有 2 个电源正在运行?

Dart protobuf : what version of protoc should I download?

firebase - 如何使用嵌套 double 据将数据添加到Firebase

Flutter:如何以印度编号格式显示货币?

events - 取消订阅事件的事件处理程序

algorithm - 如何连接列表中具有相同值的字符串列表

class - 如何从Flutter中的另一个类访问一个类的变量

android-studio - Android Studio 不会在 Flutter Outline 模式下渲染