Ошибка CarouselSlider Именованный параметр «onPageChanged» не определен - PullRequest
0 голосов
/ 21 апреля 2020

Как я могу решить эту ошибку? Именованный параметр 'onPageChanged' не определен.

Я удалил и снова добавил carousel_slider из зависимостей pubspe c .yaml. Но это не работает.


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

1 Ответ

0 голосов
/ 21 апреля 2020

Добавьте свой код внутри CarouselOptions.

CarouselSlider(
      options: CarouselOptions(
          onPageChanged: (index, reason) {
            setState(() {
              _currentPage = index;
              _currentKeyword = keywords[_currentPage];
            });
          }
      ),
    );
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...