Error: No named parameter with the name 'IndexedWidgetBuilder' in flutter

Issue

Getting this error in the flutter web. In the PageView.builder and do not how to use IndexedWidgetBuilder in the flutter project. Tried using itembuilder(context, index) but not solved. Cannot use itemcount, itembuilder in these version of flutter.

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.3, on Microsoft Windows [Version 10.0.19042.746], locale en-IN)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[√] Chrome - develop for the web
[√] Android Studio (version 3.5)
[√] VS Code (version 1.52.1)
[√] Connected device (2 available)

Code:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:website/references/ref.dart';

class Carousel extends StatefulWidget {
  @override
  _CarouselState createState() => _CarouselState();
}

class _CarouselState extends State<Carousel> {
  var _tag = "carousel.dart";

  /// [ref]
  Ref _ref = Ref();

  /// [slide images]
  final List<String> imgList = [
    "assets/slider/slide1.jpg",
    "assets/slider/slide2.jpeg",
    "assets/slider/slide3.jpeg",
    "assets/slider/slide4.jpeg",
    "assets/slider/slide5.jpg",
    "assets/slider/slide6.jpeg"
  ];

  /// [variable for carousel]
  final PageController _pageController = PageController(
    initialPage: 0,
    viewportFraction: 1,
  );

  int _currentPage = 0;

  @override
  void initState() {
    super.initState();
    try {
      Timer.periodic(Duration(seconds: 8), (Timer timer) {
        if (_currentPage < 5) {
          _currentPage++;
        } else {
          _currentPage = 0;
        }
      });
    } on Exception catch (e) {
      print("$_tag initState e : $e");
    }
  }

  @override
  void dispose() {
    super.dispose();
    _pageController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    double h = MediaQuery.of(context).size.height;
    double w = MediaQuery.of(context).size.width;

    print("$_tag h: $h");
    print("$_tag w: $w");

    return ListView(
      padding: _ref.paddnMargin.edgeInsets0,
      children: <Widget>[
        _buildImageCarosel(),
      ],
    );
  }

  // build image carosel
  Widget _buildImageCarosel() {
    Widget widget;
    try {
      widget = Container(
        height: MediaQuery.of(context).size.height / 1.5,
        width: MediaQuery.of(context).size.width,
        child: PageView.builder(
          scrollDirection: Axis.horizontal,
          controller: _pageController,
          onPageChanged: _onPageChanged,
          IndexedWidgetBuilder: _buildDynamicList,
        ),
      );
    } on Exception catch (e) {
      print("$_tag _buildImageCarosel e : $e");
    }
    return widget;
  }

  Widget _buildDynamicList() {
    return ListView.builder(
      scrollDirection: Axis.horizontal,
      padding: _ref.paddnMargin.edgeInsets0,
      IndexedWidgetBuilder: (context, index) {
        return Container(
          margin: _ref.paddnMargin.edgeInsets10A,
          child: Center(
            child: Image.asset(
              imgList[index],
              height: MediaQuery.of(context).size.height / 1.5,
              width: MediaQuery.of(context).size.width,
            ),
          ),
        );
      },
     
    );
  }

  _onPageChanged(int index) {
    setState(() {
      _currentPage = index;
    });
  }
}

Error Message :

lib/widgets/carousel.dart:122:11: Error: No named parameter with the name 'IndexedWidgetBuilder'.
          IndexedWidgetBuilder: _buildDynamicList,
          ^^^^^^^^^^^^^^^^^^^^
/C:/sdk/flutter/packages/flutter/lib/src/widgets/page_view.dart:661:3: Context: Found this candidate, but the arguments don't match.
  PageView.builder({
  ^^^^^^^^^^^^^^^^
lib/widgets/carousel.dart:140:7: Error: No named parameter with the name 'IndexedWidgetBuilder'.
      IndexedWidgetBuilder: (context, index) {
      ^^^^^^^^^^^^^^^^^^^^
/C:/sdk/flutter/packages/flutter/lib/src/widgets/scroll_view.dart:1154:3: Context: Found this candidate, but the arguments don't match.
  ListView.builder({
  ^^^^^^^^^^^^^^^^
Waiting for connection from debug service on Chrome...             23.0s
Failed to compile application.

Not getting what is the issue

Solution

Change this IndexedWidgetBuilder: (context, index) to itemBuilder: (context, index) in your _buildDynamicList() method. Check this page for the example of listview builder.

You are confusing the type of the property to its name. Thats what the error message is trying to convey saying there is no property named IndexedWidgetBuilder. The property name is itemBuilder.

Also in the PageViewBuilder replace it with itemBuilder. Check here for its documentation.

Answered By – Abhilash Chandran

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.