Skip to content

Commit

Permalink
Fix timeline scroll to end
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodoering committed Jun 25, 2022
1 parent 7cb8270 commit be522b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
21 changes: 17 additions & 4 deletions lib/components/timeline/widgets/timeline.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:built_collection/built_collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -103,10 +105,21 @@ class _TimelineState extends ConsumerState<Timeline> {
if (next.scrollToEnd) {
// scroll to the end after the list has been built
WidgetsBinding.instance.addPostFrameCallback((_) async {
await Future<void>.delayed(const Duration(milliseconds: 300));
if (_controller!.positions.length == 1) {
_controller!.jumpTo(_controller!.positions.first.maxScrollExtent);
}
final mediaQuery = MediaQuery.of(context);
await Future<void>.delayed(const Duration(milliseconds: 100));

final maxScrollExtend = _controller!.positions.fold<double>(
0,
(previousValue, element) => max(
previousValue,
element.maxScrollExtent,
),
);

_controller!.jumpTo(
// + extra height to make sure we reach the end
maxScrollExtend + mediaQuery.size.height * 3,
);
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/components/tweet/widgets/tweet_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class _TweetCardState extends ConsumerState<TweetCard> {
final state = ref.watch(provider);
final notifier = ref.watch(provider.notifier);

if (state == null) return const SizedBox();
final tweet = state ?? widget.tweet;

final delegates = widget.createDelegates(state, notifier);
final delegates = widget.createDelegates(tweet, notifier);

final child = TweetCardContent(
tweet: state,
tweet: tweet,
notifier: notifier,
delegates: delegates,
outerPadding: display.paddingValue,
Expand All @@ -66,12 +66,12 @@ class _TweetCardState extends ConsumerState<TweetCard> {
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => delegates.onShowTweet?.call(context, ref.read),
child: state.replies.isEmpty
child: tweet.replies.isEmpty
? child
: Column(
children: [
child,
TweetCardReplies(tweet: state, color: widget.color),
TweetCardReplies(tweet: tweet, color: widget.color),
],
),
),
Expand Down

0 comments on commit be522b4

Please sign in to comment.