ListView
을 reverse: true
과 함께 사용하는 경우 0.0으로 스크롤하면 원하는대로 처리됩니다.
import 'dart:collection';
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Example',
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<Widget> _messages = <Widget>[new Text('hello'), new Text('world')];
ScrollController _scrollController = new ScrollController();
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Container(
decoration: new BoxDecoration(backgroundColor: Colors.blueGrey.shade100),
width: 100.0,
height: 100.0,
child: new Column(
children: [
new Flexible(
child: new ListView(
controller: _scrollController,
reverse: true,
shrinkWrap: true,
children: new UnmodifiableListView(_messages),
),
),
],
),
),
),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.add),
onPressed:() {
setState(() {
_messages.insert(0, new Text("message ${_messages.length}"));
});
_scrollController.animateTo(
0.0,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 300),
);
}
),
);
}
}
이것은 트릭을 수행했습니다. 내 특별한 경우에는 확장 된 위젯에 ListView를 넣기 위해 중첩 된 열을 사용해야했지만 기본 아이디어는 동일합니다. – yyoon
해결책을 찾으러 왔는데, 다른 해결책이 이것을 달성하는 더 좋은 방법 일 수 있다고 언급하고 싶습니다. - https://stackoverflow.com/questions/44141148/how-to-get-full-size-of- a-scrollcontroller –
나는 그 대답에 동의한다. –