Fluent encapsulates the example code of a banner round robin effect
•
Android
CustomBanner( this._images,{ this.height = 200,this.onTap,this.curve = Curves.linear,}) : assert(_images != null);
Widget _buildPageView() { var length = widget._images.length; return Container( height: widget.height,child: PageView.builder( controller: _pageController,onPageChanged: (index) { if (index == 0) { _curIndex = length; } },itemBuilder: (context,index) { return Image.network( widget._images[index % length],fit: @R_976_2419@Fit.cover,); },),); }
_timer = Timer.periodic(Duration(seconds: 3),(t) { _curIndex++; _pageController.animateToPage( _curIndex,duration: Duration(milliseconds: 300),curve: Curves.linear,); });
return GestureDetector( onTap: () { Scaffold.of(context).showSnackBar( SnackBar( content: Text('当前 page 为 ${index % length}'),duration: Duration(milliseconds: 500),child: Image.network( widget._images[index % length],);
return Stack( alignment: Alignment.bottomCenter,children: <Widget>[ _buildViewPager(),_buildIndicator(),],);
Widget _buildIndicator() { var length = widget._images.length; return Positioned( bottom: 10,child: Row( children: widget._images.map((s) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 3.0),child: ClipOval( child: Container( width: 8,height: 8,color: Colors.grey,); }).toList(),); }
Widget _buildIndicator() { var length = widget._images.length; return Positioned( bottom: 10,color: s == widget._images[_curIndex % length] ? Colors.white : Colors.grey,); }
/// 点击到图片的时候取消定时任务 _cancelTimer() { if (_timer != null) { _timer.cancel(); _timer = null; _initTimer(); } } /// ------------------------ return GestureDetector( onPanDown: (details) { _cancelTimer(); },onTap: () { Scaffold.of(context).showSnackBar( SnackBar( content: Text('当前 page 为 ${index % length}'),);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码