I need to use ListView.builder in showDialog widget but i got error with BuildContext in ListView.builder, error said that BuildContext isn't a type here is the line in which i got error

itemBuilder: (BuildContext buildContext,int index){

and there is all my code

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
  Future<void> main() async{
  runApp(
    MaterialApp(
      title: 'Some Tests',
      home: Home(),
    ),
  );
class Home extends StatefulWidget {
  const Home({Key? key, }) : super(key: key);
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: (){
          showDialog(context: context, builder: (BuildContext){
            return Container(
              height: 300,
              width: double.maxFinite,
              child: ListView.builder(
                  itemCount: someList.length
//line below comment got error
                  itemBuilder: (BuildContext buildContext,int index){
// line above comment got error
                    return Card(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [],
                      ),
                    );
                  }
              ),
            );
          });
        },
      ),
    );
  }
}

i used a Future in main function for other stuff, but it doesn't affect the rest of the code


Solution 1: nvoigt

showDialog(context: context, builder: (BuildContext){

This line defines a variable name "BuildContext" which confuses the compiler.

Either use the full definition with type and name:

showDialog(context: context, builder: (BuildContext buildContext){

or just use the name, but do not pick a name that is also a type:

    showDialog(context: context, builder: (buildContext){