flutter_scroll_to_index

Last updated:

0 purchases

flutter_scroll_to_index Image
flutter_scroll_to_index Images
Add to Cart

Description:

flutter scroll to index

flutter_scroll_to_index #

flutter滚动组件 #
Listview 滑动到指定item,类似于定位功能
如何使用? #
1.创建控制器
final ScrollToIndexController _scrollToIndexController = ScrollToIndexController();
copied to clipboard
2.自定义模型对象
注意自定义对象一定要继承ScrollToIndexBaseObject 类
class TestObject extends ScrollToIndexBaseObject {
final String name;
final int age;
TestObject(this.name, this.age);
}
copied to clipboard
3.在页面中使用widget
使用组件ScrollToIndex
ScrollToIndex(
itemBuilder: (context, index) {
TestObject item = objs[index]; // 模型 model
return Card(
key: item.globalKey, // 必须要的,用来定位,ScrollToIndexBaseObject 的属性
elevation: 20,
margin: EdgeInsets.all(20),
child: Container(
padding: EdgeInsets.all(8),
child: Column(
children: [
Text(item.name),
Text("${item.age}"),
],
),
),
);
},
list: objs, // 必须要的 model模型列表, 是个数组
controller: _scrollToIndexController, // 必须要的 controller
)
copied to clipboard
4.滑动到指定index
使用_scrollToIndexController.to(int index)方法滑动到指定item
_scrollToIndexController.to(6);
copied to clipboard
6.销毁
_scrollToIndexController.dispose();
copied to clipboard
数组
final List<TestObject> objs = List.generate(20, (index) => TestObject("典典${index + 1}", 22 + index));
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.