Gridview.builder 从列表末尾开始
Gridview.builder start at the end of list
我在 Widget 中有一个 Gridview.builder。当我打开小部件时,我想立即跳转到网格列表的末尾。
class _StampsInTravelbookState extends State<StampsInTravelbook> {
ScrollController _scrollController = new ScrollController();
@override
Widget build(BuildContext context) {
if (_scrollController.hasClients) {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
}
return GridView.builder(
controller: _scrollController,
reverse: false,
itemCount:
Provider.of<UserPosProv>(context, listen: true).userStamps.length,
shrinkWrap: true,
但我总是把网格放在开头。
当我设置
reverse: true
网格显示列表的末尾。
我认为这对你有用
_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
duration: Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn);
``
添加userStamps.reverse()
例子
class _StampsInTravelbookState extends State<StampsInTravelbook> {
@override
Widget build(BuildContext context) {
final userStamps = Provider.of<UserPosProv>(context, listen: true).userStamps;
userStamps.reverse(); // This line makes your userStamps list reversed.
return GridView.builder(
itemCount: userStamps.length,
itemBuilder: (context, index) => // Your GridTile here,
shrinkWrap: true,
);
}
}
我在 Widget 中有一个 Gridview.builder。当我打开小部件时,我想立即跳转到网格列表的末尾。
class _StampsInTravelbookState extends State<StampsInTravelbook> {
ScrollController _scrollController = new ScrollController();
@override
Widget build(BuildContext context) {
if (_scrollController.hasClients) {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
}
return GridView.builder(
controller: _scrollController,
reverse: false,
itemCount:
Provider.of<UserPosProv>(context, listen: true).userStamps.length,
shrinkWrap: true,
但我总是把网格放在开头。
当我设置
reverse: true
网格显示列表的末尾。
我认为这对你有用
_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
duration: Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn);
``
添加userStamps.reverse()
例子
class _StampsInTravelbookState extends State<StampsInTravelbook> {
@override
Widget build(BuildContext context) {
final userStamps = Provider.of<UserPosProv>(context, listen: true).userStamps;
userStamps.reverse(); // This line makes your userStamps list reversed.
return GridView.builder(
itemCount: userStamps.length,
itemBuilder: (context, index) => // Your GridTile here,
shrinkWrap: true,
);
}
}