我是一个初学者,正在尝试构建一个构造函数来设置列表项,并在滚动到下一页时调用它们以在页面视图中查看。我尝试了太多东西,但都失败了。即使避免直接帮助来提高自己,我还是被困住了,需要帮助。
import 'package:flutter/material.dart';
class Card {
String image, name;
Card({this.image, this.name});
}
class CardBrain {
List<Card> _cardData = [
Card(image: 'images/item1.jpg', name: 'item1'),
Card(image: 'images/item2.jpg', name: 'item2'),
];
String getCard() {
return _cardData[_cardNumber].image;
}
String getname() {
return _cardData[_cardNumber].name;
}
int _cardNumber = 0;
void nextCard(int itemNumber) {
if (_cardNumber == 0;){
itemNumber++;
}
}
}
class Images extends StatefulWidget {
@override
_ImagesState createState() => _ImagesState();
}
class _ImagesState extends State<Images> {
PageController pageController = PageController();
@override
Widget build(BuildContext context) {
return Container(
child: PageView(
onPageChanged: cardBrain.nextStory(1),
controller: pageController,
children: <Widget>[
Container(
color: Colors.white,
child: Column(
children: <Widget>[
Image.asset(cardBrain.getCard(), fit: BoxFit.fitWidth),
Text(cardBrain.getname(), ),
],
),
),
],
),
);
}
}