有没有办法渲染一个列表然后滚动到底部。
我知道你可以在添加新项目时使用 ScrollController
手动滚动到底部(如这个问题:Programmatically scrolling to the end of a ListView),但我应该如何自动滚动到列表底部在未添加新项目的情况下构建列表。
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage();
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Column(
children: <Widget>[
new Expanded(
child: new ListView.builder(
itemCount: 200,
itemBuilder: (context, index) {
return new ListTile(
title: new Text("title $index"),
);
},
),
),
],
),
);
}
}
最佳答案
如果您使用 reverse: true
child: new ListView.builder(
reverse: true
https://docs.flutter.io/flutter/widgets/ListView/ListView.builder.html
关于dart - 渲染列表项然后滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50303213/