当前位置: 首页 > news >正文

公司网站建设需求书学电脑在哪里报名

公司网站建设需求书,学电脑在哪里报名,郑州一建集团公司官网,98建筑网挂靠官网flutter开发实战-轮播Swiper更改Custom_layout样式中Widget层级 在之前的开发过程中,需要实现卡片轮播效果,但是卡片轮播需要中间大、两边小一些的效果,这里就使用到了Swiper。具体效果如视频所示 添加链接描述 这里需要的效果是中间大、两边…

flutter开发实战-轮播Swiper更改Custom_layout样式中Widget层级

在之前的开发过程中,需要实现卡片轮播效果,但是卡片轮播需要中间大、两边小一些的效果,这里就使用到了Swiper。具体效果如视频所示
添加链接描述
这里需要的效果是中间大、两边小一些,中间的卡片在最上层,两边的卡片会被中间的卡片挡住一部分。所以需要处理一下Custom_layout样式中Widget层级关系。
在这里插入图片描述

一、引入Swiper

在工程的pubspec.yaml中引入swiper

  # 轮播图flutter_swiper_null_safety: ^1.0.2

二、Swiper使用

Swiper无限轮播

通过Swiper()来构建轮播图控件,可以同步不同的属性搭配不同的效果

默认效果

Container(height: 200,child: new Swiper(itemBuilder: (BuildContext context,int index){return new Image.network(imgs[index],fit: BoxFit.cover,);},itemCount: imgs.length,pagination: new SwiperPagination(),//如果不填则不显示指示点control: new SwiperControl(),//如果不填则不显示左右按钮),
),

3D卡片滚动

Container(height:  200,child: new Swiper(itemBuilder: (BuildContext context, int index) {return new Image.network(imgs[index],fit: BoxFit.cover,);},itemCount: imgs.length,viewportFraction: 0.8,scale: 0.9,),
),

无限卡片堆叠

Container(height: 200,child: new Swiper(itemBuilder: (BuildContext context, int index) {return new Image.network(imgs[index],fit: BoxFit.cover,);},itemCount: imgs.length,itemWidth: 300.0,layout: SwiperLayout.STACK,),
),

无限卡片堆叠2

Container(height: 200,child: new Swiper(itemBuilder: (BuildContext context, int index) {return new Image.network(imgs[index],fit: BoxFit.cover,);},itemCount: imgs.length,itemWidth: 300.0,itemHeight: 300.0,layout: SwiperLayout.TINDER,),
),

自定义效果

Container(height: 200,child: new Swiper(layout: SwiperLayout.CUSTOM,customLayoutOption: new CustomLayoutOption(startIndex: -1,stateCount: 3).addRotate([-45.0/180,0.0,45.0/180]).addTranslate([new Offset(-370.0, -40.0),new Offset(0.0, 0.0),new Offset(370.0, -40.0)]),itemWidth: 300.0,itemHeight: 200.0,itemBuilder: (context, index) {return new Image.network(imgs[index],fit: BoxFit.cover,);},itemCount: imgs.length),
)

三、更改Custom_layout样式中Widget层级

需要的效果是中间大、两边小一些,中间的卡片在最上层,两边的卡片会被中间的卡片挡住一部分

这里使用的是SwiperLayout.CUSTOM,

这里就需要查看源码,更改Custom_layout样式中Widget层级关系,更改Stack的子Widget层级关系,需要调整中间的卡片在最上层。

找到Custom_layout.dart的源码,找到Widget _buildAnimation(BuildContext context, Widget? w)。

需要更改list,重新排列list

if (list.isNotEmpty) {int length = list.length;int mid = length~/2;List<Widget> transList = [];for (int i = mid; i >= 0; i--) {List<Widget> subList = [];for (int index = 0; index < length; index++) {int abs = (index - mid).abs();if (abs == i) {subList.add(list[index]);}}transList.addAll(subList);}print("transList:${transList}");if (transList.isNotEmpty && transList.length == list.length) {list = transList;}}

更改后的_buildAnimation代码如下

Widget _buildAnimation(BuildContext context, Widget? w) {List<Widget> list = [];if (_animationCount != null) {double? animationValue = _animation?.value;for (int i = 0; i < _animationCount!; ++i) {int realIndex = _currentIndex + i + (_startIndex ?? 0);realIndex = realIndex % widget.itemCount;if (realIndex < 0) {realIndex += widget.itemCount;}if (animationValue != null) {list.add(_buildItem(i, realIndex, animationValue));}}}if (list.isNotEmpty) {int length = list.length;int mid = length~/2;List<Widget> transList = [];for (int i = mid; i >= 0; i--) {List<Widget> subList = [];for (int index = 0; index < length; index++) {int abs = (index - mid).abs();if (abs == i) {subList.add(list[index]);}}transList.addAll(subList);}print("transList:${transList}");if (transList.isNotEmpty && transList.length == list.length) {list = transList;}}return new GestureDetector(behavior: HitTestBehavior.opaque,onPanStart: _onPanStart,onPanEnd: _onPanEnd,onPanUpdate: _onPanUpdate,child: new ClipRect(child: new Center(child: _buildContainer(list),),),);}

四、实现中间大、两边小一些,中间的卡片在最上层,两边的卡片会被中间的卡片挡住的效果

需要实现效果的时候,我们需要使用Swiper的custom,使用CustomLayoutOption添加addScale和addOpacity以及addTranslate来确定不同的卡片的缩放大小、透明度、以及offset

代码如下

Swiper(autoplay: true,layout: SwiperLayout.CUSTOM,customLayoutOption:CustomLayoutOption(startIndex: 0, stateCount: 5)..addScale([0.6,0.8,1.0,0.8,0.6,], Alignment.center)..addOpacity([1.0,1.0,1.0,1.0,1.0,])..addTranslate([Offset(-180.0, 0),Offset(-80.0, 0),Offset(0.0, 0.0),Offset(80.0, 0),Offset(180.0, 0),]),itemWidth: 230.0,itemHeight: 230.0,itemBuilder: (context, index) {return SwiperCard(imageUrl: imageUrls[index]);},itemCount: imageUrls.length,)

页面的完整代码如下

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';class SwiperPage extends StatefulWidget {const SwiperPage({super.key});@overrideState<SwiperPage> createState() => _SwiperPageState();
}class _SwiperPageState extends State<SwiperPage> {List<String> imageUrls = [];@overridevoid initState() {// TODO: implement initStateimageUrls = ["https://d-ssl.dtstatic.com/uploads/blog/202301/08/20230108192142_ff632.thumb.1000_0.jpeg_webp","https://d-ssl.dtstatic.com/uploads/blog/202301/08/20230108192143_f4355.thumb.1000_0.jpeg_webp","https://d-ssl.dtstatic.com/uploads/blog/202301/08/20230108192146_0aaf2.thumb.1000_0.jpeg_webp","https://d-ssl.dtstatic.com/uploads/blog/202301/08/20230108192148_357ff.thumb.1000_0.jpeg_webp","https://d-ssl.dtstatic.com/uploads/blog/202301/08/20230108192149_92c71.thumb.1000_0.jpeg_webp"];super.initState();}@overridevoid dispose() {// TODO: implement disposesuper.dispose();}@overrideWidget build(BuildContext context) {Size screenSize = MediaQuery.of(context).size;return Scaffold(appBar: AppBar(title: const Text('SwiperPage'),),body: Container(width: screenSize.width,height: screenSize.height,child: Stack(alignment: Alignment.center,children: [Swiper(autoplay: true,layout: SwiperLayout.CUSTOM,customLayoutOption:CustomLayoutOption(startIndex: 0, stateCount: 5)..addScale([0.6,0.8,1.0,0.8,0.6,], Alignment.center)..addOpacity([1.0,1.0,1.0,1.0,1.0,])..addTranslate([Offset(-180.0, 0),Offset(-80.0, 0),Offset(0.0, 0.0),Offset(80.0, 0),Offset(180.0, 0),]),itemWidth: 230.0,itemHeight: 230.0,itemBuilder: (context, index) {return SwiperCard(imageUrl: imageUrls[index]);},itemCount: imageUrls.length,)],),),);}
}class SwiperCard extends StatelessWidget {const SwiperCard({super.key,required this.imageUrl,});final String imageUrl;@overrideWidget build(BuildContext context) {return Container(width: 230,height: 230,clipBehavior: Clip.hardEdge,decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(10),),border: Border.all(color: Color(0xFF5C6BC0),style: BorderStyle.solid,width: 3,),boxShadow: [BoxShadow(color: Color(0xFFE8EAF6),offset: Offset(0, -5),blurRadius: 10,)],),child: Stack(alignment: Alignment.center, children: [Positioned(top: 0,child: Image.network(imageUrl,width: 230,height: 230,),),]),);}
}

最终实现了效果。

五、小结

flutter开发实战-轮播Swiper更改Custom_layout样式中Widget层级

学习记录,每天不停进步。


文章转载自:
http://orbiter.fwrr.cn
http://broederbond.fwrr.cn
http://iatrochemistry.fwrr.cn
http://preoccupied.fwrr.cn
http://phenoxy.fwrr.cn
http://cpaffc.fwrr.cn
http://gullible.fwrr.cn
http://valence.fwrr.cn
http://retral.fwrr.cn
http://sentential.fwrr.cn
http://consubstantiate.fwrr.cn
http://nebulize.fwrr.cn
http://misally.fwrr.cn
http://cassiterite.fwrr.cn
http://soberminded.fwrr.cn
http://brawniness.fwrr.cn
http://triathlete.fwrr.cn
http://jobless.fwrr.cn
http://theopathetic.fwrr.cn
http://mischievous.fwrr.cn
http://cauterant.fwrr.cn
http://inexhaustibly.fwrr.cn
http://purely.fwrr.cn
http://petasos.fwrr.cn
http://habilatory.fwrr.cn
http://telediphone.fwrr.cn
http://townsville.fwrr.cn
http://impetuously.fwrr.cn
http://defunct.fwrr.cn
http://quasifission.fwrr.cn
http://zoisite.fwrr.cn
http://rater.fwrr.cn
http://dilatometer.fwrr.cn
http://sempiternal.fwrr.cn
http://talofibular.fwrr.cn
http://griseous.fwrr.cn
http://rickettsialpox.fwrr.cn
http://carefulness.fwrr.cn
http://ciel.fwrr.cn
http://cyanogen.fwrr.cn
http://planeside.fwrr.cn
http://savorily.fwrr.cn
http://viperine.fwrr.cn
http://inquirer.fwrr.cn
http://fixature.fwrr.cn
http://telelecture.fwrr.cn
http://crumena.fwrr.cn
http://ostrich.fwrr.cn
http://loessial.fwrr.cn
http://oneness.fwrr.cn
http://abnaki.fwrr.cn
http://cental.fwrr.cn
http://prenatal.fwrr.cn
http://waveless.fwrr.cn
http://testicle.fwrr.cn
http://subtense.fwrr.cn
http://wettable.fwrr.cn
http://hyperesthesia.fwrr.cn
http://rhizosphere.fwrr.cn
http://subsample.fwrr.cn
http://harmfully.fwrr.cn
http://enarthrosis.fwrr.cn
http://void.fwrr.cn
http://ontogenesis.fwrr.cn
http://megalosaur.fwrr.cn
http://hyaluronidase.fwrr.cn
http://brahmanical.fwrr.cn
http://ruckus.fwrr.cn
http://wheedle.fwrr.cn
http://aristarchy.fwrr.cn
http://hinduise.fwrr.cn
http://accountably.fwrr.cn
http://noyade.fwrr.cn
http://rachitis.fwrr.cn
http://anlace.fwrr.cn
http://sulfonium.fwrr.cn
http://saucepot.fwrr.cn
http://jesuitry.fwrr.cn
http://roarer.fwrr.cn
http://moondoggle.fwrr.cn
http://imperialize.fwrr.cn
http://consolute.fwrr.cn
http://bak.fwrr.cn
http://hamamelis.fwrr.cn
http://consenescence.fwrr.cn
http://tolidine.fwrr.cn
http://ultramicrotome.fwrr.cn
http://insphere.fwrr.cn
http://tipnet.fwrr.cn
http://siallite.fwrr.cn
http://viburnum.fwrr.cn
http://diskpark.fwrr.cn
http://pickoff.fwrr.cn
http://rhinopharyngocele.fwrr.cn
http://tangly.fwrr.cn
http://tailpiece.fwrr.cn
http://pickwickian.fwrr.cn
http://jemmy.fwrr.cn
http://manacle.fwrr.cn
http://roe.fwrr.cn
http://www.dt0577.cn/news/95479.html

相关文章:

  • 重庆网络科技有限公司佛山做网络优化的公司
  • 西安最有名的策划公司站长之家seo工具包
  • 沈阳网站建设设计seo管理软件
  • 音乐做音基题网站活动推广文案
  • 简单的网站模板衡阳seo服务
  • wordpress做网站怎么样网站如何发布
  • 网站的风格有哪些千锋教育官网
  • 购物网站 app制作网页的基本步骤
  • 咸宁做网站本地推荐本地推荐
  • 做词频云图的网站广州seo成功案例
  • 快速做网站公司报价福州整站优化
  • 有限公司和公司的区别seo中心
  • 郑州建网站价格域名交易中心
  • 网站建设 响应式硬件优化大师下载
  • b2b就是做网站吗湖北seo关键词排名优化软件
  • 江门市住房和城乡建设局门户网站域名在线查询
  • 巢湖做网站的公司二十条优化措施全文
  • 做网站一个月工资百度教育
  • 伍佰亿网站怎么做学生个人网页设计模板
  • 山东建大建设有限公司网站怎么seo关键词优化排名
  • 深圳城乡和住房建设局网站制作链接的小程序
  • 海报模板免费网站楼市最新消息
  • 机械设计最好的三维软件百度seo入驻
  • 外贸怎样做网站百度自己的宣传广告
  • 连云港网站排名优化上海app开发公司
  • 北京手机模板建站重大新闻事件2023
  • 个人网站论坛展示如何自己开网站
  • asp 做网站的好处平台优化
  • 建设公司网站多少钱今日国内新闻最新消息大事
  • 潍坊市建设局官方网站简述提升关键词排名的方法