CarouselSlider错误未定义命名参数'onPageChanged'

问题描述 投票:0回答:1

如何解决此错误?未定义命名参数'onPageChanged'。

我从pubspec.yaml的依赖项中删除并重新添加了carousel_slider。但这不起作用。


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
flutter dart parameters yaml carousel
1个回答
0
投票

将您的代码添加到CarouselOptions中。

CarouselSlider(
      options: CarouselOptions(
          onPageChanged: (index, reason) {
            setState(() {
              _currentPage = index;
              _currentKeyword = keywords[_currentPage];
            });
          }
      ),
    );
© www.soinside.com 2019 - 2024. All rights reserved.