如何解决此错误? 未定义命名参数“ 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
答案 0 :(得分:0)
将代码添加到CarouselOptions
内。
CarouselSlider(
options: CarouselOptions(
onPageChanged: (index, reason) {
setState(() {
_currentPage = index;
_currentKeyword = keywords[_currentPage];
});
}
),
);