From 229f1a3ee776bec207e36cf19fcb4d8e6daaa5e5 Mon Sep 17 00:00:00 2001 From: Bretton Date: Sun, 14 Dec 2025 23:32:03 -0800 Subject: [PATCH] feat(post): support optimistic post navigation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add isOptimistic flag to PostDetailScreen to skip initial comment loading for newly created posts that haven't been indexed yet. Also adds AlwaysScrollableScrollPhysics for consistent pull-to-refresh. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/screens/home/post_detail_screen.dart | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/screens/home/post_detail_screen.dart b/lib/screens/home/post_detail_screen.dart index 7f4b94d..483e15d 100644 --- a/lib/screens/home/post_detail_screen.dart +++ b/lib/screens/home/post_detail_screen.dart @@ -37,11 +37,15 @@ import 'focused_thread_screen.dart'; /// - Loading, empty, and error states /// - Automatic comment loading on screen init class PostDetailScreen extends StatefulWidget { - const PostDetailScreen({required this.post, super.key}); + const PostDetailScreen({required this.post, this.isOptimistic = false, super.key}); /// Post to display (passed via route extras) final FeedViewPost post; + /// Whether this is an optimistic post (just created, not yet indexed) + /// When true, skips initial comment load since we know there are no comments + final bool isOptimistic; + @override State createState() => _PostDetailScreenState(); } @@ -122,8 +126,13 @@ class _PostDetailScreenState extends State { // Listen for changes to trigger rebuilds _commentsProvider.addListener(_onProviderChanged); - // Check if we already have cached data - if (_commentsProvider.comments.isNotEmpty) { + // Skip loading for optimistic posts (just created, not yet indexed) + if (widget.isOptimistic) { + if (kDebugMode) { + debugPrint('✨ Optimistic post - skipping initial comment load'); + } + // Don't load comments - there won't be any yet + } else if (_commentsProvider.comments.isNotEmpty) { // Already have data - restore scroll position immediately if (kDebugMode) { debugPrint( @@ -668,6 +677,7 @@ class _PostDetailScreenState extends State { color: AppColors.primary, child: CustomScrollView( controller: _scrollController, + physics: const AlwaysScrollableScrollPhysics(), slivers: [ // Floating app bar that hides on scroll down, // shows on scroll up -- 2.51.2