skip to Main Content
     Center(                     //1
       child: ListView(
          children:const [
            ListTile(
              leading: Icon(Icons.map),
              title: Text('map'),
            ),
            ListTile(
              leading: Icon(Icons.phone),
              title: Text('phone'),
            ),
            ListTile(
              leading: Icon(Icons.photo_album),
              title: Text('album'),
            ),
          ],
        ),
     ),

Please explain me why this error has occured.This is the error Too many positional arguments: 0 expected, but 1 found.

2

Answers


  1. i tried your code and there’s no error at all. i think it might be other than that listview is causing the error. try to check your debug console message

    this is the code I tried

    
    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatefulWidget {
      const MyApp({super.key});
    
      @override
      State<MyApp> createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
              body: Center(
            child: ListView(
              children: const [
                ListTile(
                  leading: Icon(Icons.map),
                  title: Text('map'),
                ),
                ListTile(
                  leading: Icon(Icons.phone),
                  title: Text('phone'),
                ),
                ListTile(
                  leading: Icon(Icons.photo_album),
                  title: Text('album'),
                ),
              ],
            ),
          )),
        );
      }
    }
    
    

    enter image description here

    and the code work without any error/problem

    Login or Signup to reply.
  2. I guess this is going to work for you but try it.I would recommend you to not use ListView but ListView.builder,Just follow the next example.

    //First create these lists.
    List<String> _titles = [
    'map',
    'phone',
    'album',
    ];
    
    List<IconData> _icons = [
    Icons.map,
    Icons.phone,
    Icons.album,
    ];
    

    Then return ListView.builder like this.

    ListView.builder(
      itemCount: _titles.length,
      itemBuilder: ((context, index) {
        return ListTile(
          title: Text(
            _titles[index],
          ),
          leading: Icon(
            _icons[index],
          ),
        );
      }),
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search