我使用他们的管理,以同步多个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等)



