From 0cba3f9e3fe51a5ee9a83011be5a2bce3fab9bee Mon Sep 17 00:00:00 2001 From: Richard Shiue <71320345+richardshiue@users.noreply.github.com> Date: Sun, 1 Dec 2024 13:18:20 +0800 Subject: [PATCH] fix(mobile): lost initial scroll position on empty ai chat page (#6895) --- .../presentation/chat_welcome_page.dart | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_welcome_page.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_welcome_page.dart index ac9536632c..6c3dd4bd4d 100644 --- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_welcome_page.dart +++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_welcome_page.dart @@ -180,7 +180,7 @@ class WelcomeSampleQuestion extends StatelessWidget { } } -class _AutoScrollingSampleQuestions extends StatelessWidget { +class _AutoScrollingSampleQuestions extends StatefulWidget { const _AutoScrollingSampleQuestions({ super.key, required this.questions, @@ -194,17 +194,29 @@ class _AutoScrollingSampleQuestions extends StatelessWidget { final double offset; final bool reverse; + @override + State<_AutoScrollingSampleQuestions> createState() => + _AutoScrollingSampleQuestionsState(); +} + +class _AutoScrollingSampleQuestionsState + extends State<_AutoScrollingSampleQuestions> { + late final scrollController = ScrollController( + initialScrollOffset: widget.offset, + ); + @override Widget build(BuildContext context) { return SizedBox( height: 36, child: InfiniteScrollView( + scrollController: scrollController, centerKey: UniqueKey(), - itemCount: questions.length, + itemCount: widget.questions.length, itemBuilder: (context, index) { return WelcomeSampleQuestion( - question: questions[index], - onSelected: onSelected, + question: widget.questions[index], + onSelected: widget.onSelected, ); }, separatorBuilder: (context, index) => const HSpace(8),