Home > Software engineering >  Too many positional argument on ListView
Too many positional argument on ListView

Time:02-17

I'm writing the test code of the ListView. Though I specified the name of parameters explicitly, I got the error message, 'Too many positional arguments: 0 expected, but 2 found'. Any suggestion to solve this?

Thanks in advance.

@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))))));
  }

CodePudding user response:

It seems you put the ListView.Builder() and GestureDetector() into Column() widget incorrectly.

Here is a correct sample:

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

When adding values for Column() and Row() you will need to add it into the children: property.

  • Related