Skip to content

Commit

Permalink
fixed issue in user profile where comments would not scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
hjiangsu committed Jun 29, 2023
1 parent 0255032 commit 27d383d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -11,6 +12,7 @@ import 'package:thunder/community/widgets/post_card_view_comfortable.dart';
import 'package:thunder/community/widgets/post_card_view_compact.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/core/theme/theme.dart';
import 'package:thunder/post/bloc/post_bloc.dart' as post_bloc; // renamed to prevent clash with VotePostEvent, etc from community_bloc
import 'package:thunder/post/pages/post_page.dart';
import 'package:thunder/post/widgets/comment_card.dart';
Expand Down Expand Up @@ -43,6 +45,7 @@ class _PostCardState extends State<PostCard> {
final bool isUserLoggedIn = context.read<AuthBloc>().state.isLoggedIn;
final bool useCompactView = context.read<ThunderBloc>().state.preferences?.getBool('setting_general_use_compact_view') ?? false;
final bool disableSwipeActionsOnPost = context.read<ThunderBloc>().state.preferences?.getBool('setting_post_disable_swipe_actions') ?? false;
final bool useDarkTheme = context.read<ThemeBloc>().state.useDarkTheme;

final bool hideNsfwPreviews = context.read<ThunderBloc>().state.preferences?.getBool('setting_general_hide_nsfw_previews') ?? true;
final bool showThumbnailPreviewOnRight = context.read<ThunderBloc>().state.preferences?.getBool('setting_compact_show_thumbnail_on_right') ?? false;
Expand Down Expand Up @@ -139,8 +142,8 @@ class _PostCardState extends State<PostCard> {
children: [
Divider(
height: 1.0,
thickness: 2.0,
color: theme.textTheme.bodyMedium?.color?.withOpacity(0.20),
thickness: 4.0,
color: useDarkTheme ? theme.colorScheme.background.lighten(5) : theme.colorScheme.background.darken(5),
),
InkWell(
child: useCompactView
Expand Down
28 changes: 27 additions & 1 deletion lib/user/pages/user_page_success.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:lemmy_api_client/v3.dart';
import 'package:thunder/community/widgets/post_card_list.dart';

import 'package:thunder/core/models/comment_view_tree.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/post/widgets/comment_view.dart';
import 'package:thunder/user/bloc/user_bloc.dart';
import 'package:thunder/utils/date_time.dart';

const List<Widget> userOptionTypes = <Widget>[
Expand Down Expand Up @@ -40,6 +42,25 @@ class UserPageSuccess extends StatefulWidget {
class _UserPageSuccessState extends State<UserPageSuccess> {
int selectedUserOption = 0;
final List<bool> _selectedUserOption = <bool>[true, false];
final _scrollController = ScrollController(initialScrollOffset: 0);

@override
void initState() {
_scrollController.addListener(_onScroll);
super.initState();
}

@override
void dispose() {
_scrollController.removeListener(_onScroll);
super.dispose();
}

void _onScroll() {
if (_scrollController.position.pixels >= _scrollController.position.maxScrollExtent * 0.8) {
context.read<UserBloc>().add(const GetUserEvent());
}
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -70,7 +91,12 @@ class _UserPageSuccessState extends State<UserPageSuccess> {
),
const SizedBox(height: 12.0),
Expanded(
child: selectedUserOption == 0 ? PostCardList(postViews: widget.posts, personId: widget.userId, hasReachedEnd: widget.hasReachedPostEnd) : CommentSubview(comments: widget.comments ?? []),
child: selectedUserOption == 0
? PostCardList(postViews: widget.posts, personId: widget.userId, hasReachedEnd: widget.hasReachedPostEnd)
: SingleChildScrollView(
controller: _scrollController,
child: CommentSubview(comments: widget.comments ?? []),
),
),
],
),
Expand Down

0 comments on commit 27d383d

Please sign in to comment.