栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

同步滚动多个可滚动小部件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

同步滚动多个可滚动小部件

我使用他们的管理,以同步多个scrollables

offset
,利用他们
ScrollNotification

这是一个粗略的代码示例:

class _MyHomePageState extends State<MyHomePage> {  ScrollController _mycontroller1 = new ScrollController(); // make seperate controllers  ScrollController _mycontroller2 = new ScrollController(); // for each scrollables  @override  Widget build(BuildContext context) {    body:      Container(        height: 100,        child: NotificationListener<ScrollNotification>( // this part right here is the key          Stack( children: <Widget>[ SingleChildScrollView( // this one stays at the back   controller: _mycontroller1,   child: Column( children: <Widget>[     Text('LEFT '),     Text('LEFT '),     Text('LEFT '),     Text('LEFT '),     Text('LEFT '),     Text('LEFT '),   ],) ), SingleChildScrollView( // this is the one you scroll   controller: _mycontroller2,   child: Column(children: <Widget>[     Text('          RIGHT'),     Text('          RIGHT'),     Text('          RIGHT'),     Text('          RIGHT'),     Text('          RIGHT'),     Text('          RIGHT'),   ],) ),          ]),          onNotification: (ScrollNotification scrollInfo) {  // HEY!! LISTEN!! // this will set controller1's offset the same as controller2's _mycontroller1.jumpTo(_mycontroller2.offset); // you can check both offsets in terminal print('check -- offset Left: '+_mycontroller1.offset.toInt().toString()+ ' -- offset Right: '+_mycontroller2.offset.toInt().toString());}        )      )}}

基本上每个人

SingleChildScrollView
都有自己的
controller
。每个
controller
都有自己的
offset
价值观。
NotificationListener<ScrollNotification>
滚动滚动时,使用通知任何移动。

然后对于每个滚动手势(我相信这是一帧一帧的基础),我们可以随意添加

jumpTo()
命令来设置
offset

干杯!!

PS。如果列表的长度不同,则偏移量将不同,并且如果尝试滚动超过其限制,则会收到堆栈溢出错误。确保添加一些异常或错误处理。(即

if else
等)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/404274.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号