Make events page remember scroll position when changing layouts.

This commit is contained in:
Shawn 2023-02-16 10:02:34 -07:00
parent 92038ed12a
commit d4d27751eb
2 changed files with 14 additions and 2 deletions

View File

@ -7,18 +7,23 @@ class _EventsList extends StatefulWidget {
this.topHeight = 0,
this.blurOnScroll = false,
this.showTopGradient = true,
required this.initialScrollOffset,
required this.onScroll,
}) : super(key: key);
final WonderData data;
final double topHeight;
final bool blurOnScroll;
final bool showTopGradient;
final double initialScrollOffset;
final void Function(double offset) onScroll;
@override
State<_EventsList> createState() => _EventsListState();
}
class _EventsListState extends State<_EventsList> {
final ScrollController _scroller = ScrollController();
late final ScrollController _scroller = ScrollController(initialScrollOffset: widget.initialScrollOffset)
..addListener(() => widget.onScroll(_scroller.offset));
@override
void dispose() {
_scroller.dispose();

View File

@ -24,6 +24,9 @@ class WonderEvents extends StatelessWidget {
final WonderType type;
late final _data = wondersLogic.getData(type);
double _scrollPos = 0;
void _handleScroll(double pos) => _scrollPos = pos;
@override
Widget build(BuildContext context) {
void handleTimelineBtnPressed() => context.push(ScreenPaths.timeline(type));
@ -102,6 +105,8 @@ class WonderEvents extends StatelessWidget {
data: _data,
topHeight: 100,
blurOnScroll: false,
onScroll: _handleScroll,
initialScrollOffset: _scrollPos,
),
),
),
@ -130,6 +135,8 @@ class WonderEvents extends StatelessWidget {
topHeight: topHeight,
blurOnScroll: true,
showTopGradient: false,
onScroll: _handleScroll,
initialScrollOffset: _scrollPos,
),
),
Gap($styles.insets.lg),