I have a list of report items.
I initialised a scrollController here:
class ReportList extends StatelessWidget {
ReportList({Key? key}) : super(key: key);
final ScrollController scrollController = ScrollController();
scrollDown() {
scrollController.animateTo(scrollController.position.maxScrollExtent,
duration: const Duration(seconds: 1), curve: Curves.bounceOut);
}
I also have a list view with the controller, and I want the list view to stroll to bottom when the last item is selected:
ListView.separated(
controller: scrollController,
itemCount: 13,
itemBuilder: (_, index) {
return Column(
children: [
ReportItem(
onClick: () {
viewModel.setCommentReportStat(index);
if (index == 12 && viewModel.commentReportStat[12]) {
scrollDown();
}
debugPrint(viewModel.commentReportStat.toString());
},
isSelected: viewModel.commentReportStat[index],
title: CommentReport.items[index],
),
//show additional message field to the user
if (index == 12 && viewModel.commentReportStat[12])
AnimatedContainer(
duration: const Duration(seconds: 1),
child: MessageField(commentId: commentId),
)
],
);
},
separatorBuilder: (_, index) => const SizedBox(
height: 16,
),
)
Everything about the state management works since the message field appears as the user clicks on the last item.
My problem in general is that neither does message field appear with the animated container which is wrapped around it, nor does it scroll down!
(If I scroll manually, I can see the entire message field, but I want this to be automated using the scroll controller)