Ad

CarouselSlider Error The Named Parameter 'onPageChanged' Isn't Defined

- 1 answer

How can I solve this error? The named parameter 'onPageChanged' isn't defined.

I removed and re-added the carousel_slider from the dependencies of pubspec.yaml. But it doesn't work.


import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';

...

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(20),
          ),
          CarouselSlider(
            items: images,
            onPageChanged: (index){
              setState(() {
                _currentPage = index;
                _currentKeyword = keywords[_currentPage];
              });
            },
          ),

dependen[enter image description here][1]cies:
  flutter:
    sdk: flutter

  carousel_slider:
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
Ad

Answer

Add your code inside the CarouselOptions.

CarouselSlider(
      options: CarouselOptions(
          onPageChanged: (index, reason) {
            setState(() {
              _currentPage = index;
              _currentKeyword = keywords[_currentPage];
            });
          }
      ),
    );
Ad
source: stackoverflow.com
Ad