[英]flutter dot indicator to pageview
I want to add a dot indicator to pageview.我想在页面浏览中添加一个点指示器。 When a person scrolls the image to the right to left image changes on my code.当一个人将图像从右向左滚动时,我的代码中的图像会发生变化。 NO problem with there but I couldn't manage to add a dot indicator to my code.那里没问题,但我无法在我的代码中添加点指示器。 How can I put a dot indicator when I scroll across images also the dots switch to the order of images.........................................................................................................当我滚动图像时如何放置点指示器并且点切换到图像的顺序...................................... ………………………………………………………………………………………………………………………………………………………… ......................................
PageView.builder(
itemCount: totalCards.toInt(),
itemBuilder: (context, i) {
return Container(
margin: EdgeInsets.only(top: 10),
child: Container(
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: PageView(
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(4.0),
image: DecorationImage(
image: AssetImage(
photos[startphoto]),
fit: BoxFit.cover)),
),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(4.0),
image: DecorationImage(
image: AssetImage(
photos[startphoto1]),
fit: BoxFit.cover)),
),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(4.0),
image: DecorationImage(
image: AssetImage(
photos[startphoto2]),
fit: BoxFit.fitHeight)),
),
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(4.0),
image: DecorationImage(
image: AssetImage(
photos[startphoto3]),
fit: BoxFit.cover)),
),
],
),
),
],
),
)
);
},
),
),
You can do that with this package: https://pub.dev/packages/page_view_indicators你可以用这个包做到这一点: https : //pub.dev/packages/page_view_indicators
In the example you can see how to implement it.在示例中,您可以看到如何实现它。
EDIT: Implement your dot indicator like this:编辑:像这样实现你的点指示器:
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
final ValueNotifier<int> _pageNotifier = new ValueNotifier<int>(0);
final PageController _pageController = new PageController();
@override
Widget build(BuildContext context) {
return Column(
children: [
PageView.builder(
itemCount: totalCards.toInt(),
controller: _pageController,
itemBuilder: (context, i) {
...
},
onPageChanged:(index) {
setState(() {
_pageNotifier.value = index;
});
},
),
Center(
child: CirclePageIndicator(
currentPageNotifier: _pageNotifier,
itemCount: totalCards.toInt(),
),
)
],
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.