ListView 上的位置参数太多

Too many positional argument on ListView

我正在写ListView的测试代码。虽然我明确指定了参数名称,但我收到了错误消息 'Too many positional arguments: 0 expected, but 2 found'。有什么解决这个问题的建议吗?

提前致谢。

@override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('File Example'),
        ),
        body: Center(
            child: Column(
                ListView.builder(
                    itemCount: (this.ideaCount == null) ? 0 : this.ideaCount,
                    itemBuilder: (BuildContext context, int position) {
                      return Card(
                        color: Colors.white,
                        elevation: 2.0,
                        child: ListTile(
                          title: Text(ideaList[position].name),
                          subtitle: Text(ideaList[position].memo),
                        )
                      );
                    }),
                GestureDetector(
                    onLongPress: () async {
                      print("Long Press");
                      result = await record.hasPermission();
                      if (result) {
                        var dir = await getApplicationDocumentsDirectory();
                        print("############");
                        print(dir.path);
                        DateTime now = DateTime.now();
                        recordDate = '$now';
                        await record.start(
                          path: dir.path + recordDate! + '.aac',
                          encoder: AudioEncoder.AAC,
                          bitRate: 128000,
                          samplingRate: 44100,
                        );
                      } else {
                        print('##########Not Allowed!!!!!');
                      }
                    },
                    onLongPressUp: () async {
                      print("Long Press Stop");
                      record.stop();
                      Idea idea = Idea(1, recordDate!, 'test');
                      helper.insertIdea(idea);
                      setState(() {
                        showData();
                      });
                    },
                    child: ElevatedButton(
                        onPressed: () {}, child: Icon(Icons.mic))))));
  }

您似乎将 ListView.Builder()GestureDetector() 错误地放入了 Column() 小部件。

这是一个正确的示例:

Column(
   children:[
       ListView.Builder(),
       GestureDetector(),
   ],
)

添加 Column()Row() 的值时,您需要将其添加到 children: 属性.