我想为这个ListTile应用自动滚动。
Container(
height: 70,
width: double.maxFinite,
child: ListView.builder(
controller: _controller,
key: itemKey,
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('demo ${index + 1}'),
);
},
),
),
我声明了这个
final itemKey = GlobalKey();
final _controller = ScrollController();
我把这个放在了小部件构建之后...
if (_controller.hasClients) {
_controller.animateTo(_controller.position.maxScrollExtent,
duration: const Duration(milliseconds: 500), curve: Curves.easeInOut);
}