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

Flutter开发 SingleChildScrollView、ScrollController

SingleChildScrollView

滑动组件

有多张图片,左右滑动
请添加图片描述

class MyState extends State {bool flag = false;Widget build(BuildContext context) {double width = MediaQuery.of(context).size.width;double height = MediaQuery.of(context).size.height / 3;SingleChildScrollView singleChildScrollView = SingleChildScrollView(scrollDirection: Axis.horizontal,child: Row(children: [Image.network("https://pic.rmb.bdstatic.com/bjh/other/d1913ba5338a6ae4571a3d8e4ce469bf.png?for=bg",width: width,height: height,fit: BoxFit.cover,),Image.network("https://pic.rmb.bdstatic.com/bjh/3eacb728ac/240814/0c5c4e7a79d45ef72c1f934e9ed7edc6.jpeg",width: width,height: height,fit: BoxFit.cover,),Image.network("https://pic.rmb.bdstatic.com/bjh/other/d1913ba5338a6ae4571a3d8e4ce469bf.png?for=bg",width: width,height: height,fit: BoxFit.cover,),Image.network("https://pic.rmb.bdstatic.com/bjh/other/d1913ba5338a6ae4571a3d8e4ce469bf.png?for=bg",width: width,height: height,fit: BoxFit.cover,),],),);return Scaffold(appBar: AppBar(title: Text("SwitchListTile"), centerTitle: true),body: singleChildScrollView,);}
}

ScrollController

控制滑动

属性说明
initialScrollOffset设置滚动视图的初始位置
keepScrollOffset设置是否保存滚动位置
offset返回当前滚动位置的偏移量
jumpTo设置滚动到指定位置
animateTo设置带动画滚动到指定位置

在上面的例子中,添加按钮,用来滑动图片,只设置一个按钮。

请添加图片描述

class MyState extends State {bool flag = false;Widget build(BuildContext context) {double width = MediaQuery.of(context).size.width;double height = MediaQuery.of(context).size.height / 3;ScrollController scrollController = ScrollController();SingleChildScrollView singleChildScrollView = SingleChildScrollView(controller: scrollController,scrollDirection: Axis.horizontal,child: Row(children: [Image.network("https://pic.rmb.bdstatic.com/bjh/other/d1913ba5338a6ae4571a3d8e4ce469bf.png?for=bg",width: width,height: height,fit: BoxFit.cover,),Image.network("https://pic.rmb.bdstatic.com/bjh/3eacb728ac/240814/0c5c4e7a79d45ef72c1f934e9ed7edc6.jpeg",width: width,height: height,fit: BoxFit.cover,),Image.network("https://pic.rmb.bdstatic.com/bjh/other/d1913ba5338a6ae4571a3d8e4ce469bf.png?for=bg",width: width,height: height,fit: BoxFit.cover,),Image.network("https://pic.rmb.bdstatic.com/bjh/other/d1913ba5338a6ae4571a3d8e4ce469bf.png?for=bg",width: width,height: height,fit: BoxFit.cover,),],),);Stack stack = Stack(alignment: Alignment.centerRight,children: [singleChildScrollView,IconButton(onPressed: () {var old = scrollController.offset;scrollController.jumpTo(old +width);}, icon: Icon(Icons.navigate_next))],);return Scaffold(appBar: AppBar(title: Text(""), centerTitle: true),body: stack,);}
}
http://www.xdnf.cn/news/17269.html

相关文章:

  • 液体泄漏识别误报率↓76%:陌讯多模态融合算法实战解析
  • camera人脸识别问题之二:【FFD】太阳逆光场景,人像模式后置打开美颜和滤镜,关闭heif拍摄格式对着人脸拍照,成像口红出现位置错误
  • 北京安全员C练习题
  • Xiphos Q8 摄像头板 高性能图像处理板
  • 恒科持续低迷:新能源汽车股下跌成拖累,销量担忧加剧
  • C++编程之旅-- -- --类与对象的奇幻征途之初识篇(一)(了解类的基本用法,计算类大小,分析this指针)
  • 快速上手 Ollama:强大的开源语言模型框架
  • GitLab同步提交的用户设置
  • 论文reading学习记录7 - daily - ViP3D
  • 日本站群服务器与普通日本服务器对比
  • Spring AMQP 入门与实践:整合 RabbitMQ 构建可靠消息系统
  • 【接口自动化测试】---requests模块
  • SpringBoot的profile加载
  • 可编辑51页PPT | 某鞋服品牌集团数字化转型项目建议书
  • 微服务如何保证系统高可用?
  • iOS 签名证书全流程详解,申请、管理与上架实战
  • 腾讯iOA:数据安全的港湾
  • 0_外设学习_ESP8266+云流转(no 0基础)
  • 最新的GPT5效果如何,我试了一下(附加GPT5大模型免费使用方法)
  • 力扣-189.轮转数组
  • 秋招笔记-8.8
  • 《Leetcode》-面试题-hot100-链表
  • django uwsgi启动报错failed to get the Python codec of the filesystem encoding
  • Android 系统的安全 和 三星安全的区别
  • C++信息学奥赛一本通-第一部分-基础一-第3章-第1节
  • RAG初步实战:从 PDF 到问答:我的第一个轻量级 RAG 系统(附详细项目代码内容与说明)
  • 2025年渗透测试面试题总结-07(题目+回答)
  • 系统网络端口安全扫描脚本及详解
  • Chrome与Firefox浏览器安全运维配置命令大全:从攻防到优化的专业实践
  • 分治-快排-215.数组中的第k个最大元素-力扣(LeetCode)