fix(mobile): lost initial scroll position on empty ai chat page (#6895)

This commit is contained in:
Richard Shiue 2024-12-01 13:18:20 +08:00 committed by GitHub
parent 81960a7f05
commit 0cba3f9e3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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),