Too many positional arguments

Hello All,

Got stuck up in a tutorial. Please someone guide me.

Here is the coding:

import 'package:flutter/material.dart';
import 'package:world_time/services/world_time.dart';

class ChooseLocation extends StatefulWidget {
  @override
  _ChooseLocationState createState() => _ChooseLocationState();
}

class _ChooseLocationState extends State<ChooseLocation> {

  List<WorldTime> locations = [
    WorldTime(url: 'Europe/London', location: 'London', flag: 'uk.png'),
    WorldTime(url: 'Europe/Berlin', location: 'Athens', flag: 'greece.png'),
    WorldTime(url: 'Africa/Cairo', location: 'Cairo', flag: 'egypt.png'),
    WorldTime(url: 'Africa/Nairobi', location: 'Nairobi', flag: 'kenya.png'),
    WorldTime(url: 'America/Chicago', location: 'Chicago', flag: 'usa.png'),
    WorldTime(url: 'America/New_York', location: 'New York', flag: 'usa.png'),
    WorldTime(url: 'Asia/Seoul', location: 'Seoul', flag: 'south_korea.png'),
    WorldTime(url: 'Asia/Jakarta', location: 'Jakarta', flag: 'indonesia.png'),
  ];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[400],
      appBar: AppBar(
        backgroundColor: Colors.blue[900],
        title: Text('Choose a Location'),
        centerTitle: true,
        elevation: 0,
      ),

      body: ListView.builder(
        itemCount: locatons.length,
        itemBuilder: (context, index), {
          return Card(
          child: ListTile(
          onTap: () {},
          title: Text(locations[index].location),
          ),
          );
      }

      ),

    );
  }
}

For this I got an error:

error: Too many positional arguments: 0 expected, but 1 found. (extra_positional_arguments_could_be_named at [world_time] lib\pages\choose_location.dart:38)
error: Expected to find ‘)’. (expected_token at [world_time] lib\pages\choose_location.dart:40)
error: The argument type ‘BuildContext’ can’t be assigned to the parameter type ‘Widget Function(BuildContext, int)’. (argument_type_not_assignable at [world_time] lib\pages\choose_location.dart:40)
error: Positional arguments must occur before named arguments. (positional_after_named_argument at [world_time] lib\pages\choose_location.dart:40)
error: Unexpected text ‘return’. (unexpected_token at [world_time] lib\pages\choose_location.dart:41)
error: Undefined name ‘index’. (undefined_identifier at [world_time] lib\pages\choose_location.dart:44)
error: Expected to find ‘}’. (expected_token at [world_time] lib\pages\choose_location.dart:46)
info: Unused import: ‘package:flutter/cupertino.dart’. (unused_import at [world_time] lib\services\world_time.dart:1)

Thanks & someone help me,
Regards,
Kannan

Hello, maybe it’s unrelated but I think you have a typo there, I’d expect some
itemCount: locations.length,

Hello Patrick,

Thanks for your feedback. Yes, you are right and some silly mistakes. Again thanks.

With Kind Regards,
Kannan