Skip to content

Commit

Permalink
Merge pull request #2493 from acterglobal/kumar/scroll-fixing
Browse files Browse the repository at this point in the history
Chat List Fixes
  • Loading branch information
kumarpalsinh25 authored Jan 13, 2025
2 parents 1246daa + 148e261 commit 229ca1f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 76 deletions.
60 changes: 25 additions & 35 deletions app/lib/features/chat/widgets/chats_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,22 @@ class ChatsList extends ConsumerWidget {
return filteredChats.when(
data: (chatsIds) {
if (chatsIds.isEmpty) {
return SliverToBoxAdapter(
child: Center(
heightFactor: 10,
child: Text(lang.noChatsFoundMatchingYourFilter),
),
return Center(
heightFactor: 10,
child: Text(lang.noChatsFoundMatchingYourFilter),
);
}
return _renderList(context, chatsIds);
},
loading: () => const SliverToBoxAdapter(
child: Center(
heightFactor: 10,
child: CircularProgressIndicator(),
),
loading: () => Center(
heightFactor: 10,
child: CircularProgressIndicator(),
),
error: (e, s) {
_log.severe('Failed to filter convos', e, s);
return SliverToBoxAdapter(
child: Center(
heightFactor: 10,
child: Text(lang.searchingFailed(e)),
),
return Center(
heightFactor: 10,
child: Text(lang.searchingFailed(e)),
);
},
skipLoadingOnReload: true,
Expand All @@ -77,31 +71,27 @@ class ChatsList extends ConsumerWidget {

Widget _renderSyncing(BuildContext context) {
final lang = L10n.of(context);
return SliverToBoxAdapter(
child: Center(
heightFactor: 1.5,
child: EmptyState(
title: lang.noChatsStillSyncing,
subtitle: lang.noChatsStillSyncingSubtitle,
image: 'assets/images/empty_chat.svg',
),
return Center(
heightFactor: 1.5,
child: EmptyState(
title: lang.noChatsStillSyncing,
subtitle: lang.noChatsStillSyncingSubtitle,
image: 'assets/images/empty_chat.svg',
),
);
}

Widget _renderEmpty(BuildContext context) {
final lang = L10n.of(context);
return SliverToBoxAdapter(
child: Center(
heightFactor: 1.5,
child: EmptyState(
title: lang.youHaveNoDMsAtTheMoment,
subtitle: lang.getInTouchWithOtherChangeMakers,
image: 'assets/images/empty_chat.svg',
primaryButton: ActerPrimaryActionButton(
onPressed: () => context.pushNamed(Routes.createChat.name),
child: Text(lang.sendDM),
),
return Center(
heightFactor: 1.5,
child: EmptyState(
title: lang.youHaveNoDMsAtTheMoment,
subtitle: lang.getInTouchWithOtherChangeMakers,
image: 'assets/images/empty_chat.svg',
primaryButton: ActerPrimaryActionButton(
onPressed: () => context.pushNamed(Routes.createChat.name),
child: Text(lang.sendDM),
),
),
);
Expand Down Expand Up @@ -245,7 +235,7 @@ class __AnimatedChatsListState extends State<_AnimatedChatsList> {
@override
Widget build(BuildContext context) {
_log.fine('render list $_currentList');
return SliverAnimatedList(
return AnimatedList(
key: _listKey,
initialItemCount: _currentList.length,
itemBuilder: buildItem,
Expand Down
73 changes: 38 additions & 35 deletions app/lib/features/chat/widgets/rooms_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';

final bucketGlobal = PageStorageBucket();

typedef RoomSelectAction = Function(String);

class RoomsListWidget extends ConsumerStatefulWidget {
Expand Down Expand Up @@ -155,44 +156,48 @@ class RoomsListWidgetState extends ConsumerState<RoomsListWidget> {

@override
Widget build(BuildContext context) {
return PageStorage(
bucket: bucketGlobal,
child: CustomScrollView(
controller: controller,
key: const PageStorageKey<String>('convo-list'),
physics: const BouncingScrollPhysics(),
slivers: [
SliverAppBar(
automaticallyImplyLeading: false,
floating: true,
elevation: 0,
leading: Padding(
padding: const EdgeInsets.all(15),
child: roomListTitle(context),
),
leadingWidth: double.infinity,
actions: renderActions(),
),
SliverToBoxAdapter(
child: AnimatedOpacity(
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
elevation: 0,
leading: Padding(
padding: const EdgeInsets.all(15),
child: roomListTitle(context),
),
leadingWidth: double.infinity,
actions: renderActions(),
),
body: PageStorage(
bucket: bucketGlobal,
child: Column(
children: [
AnimatedOpacity(
opacity: !_isSearchVisible ? 0 : 1,
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 400),
child: _isSearchVisible
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: filterBox(context),
)
padding: const EdgeInsets.symmetric(horizontal: 16),
child: filterBox(context),
)
: const SizedBox.shrink(),
),
),
SliverToBoxAdapter(
child: searchTerms(context),
),
ref.watch(isGuestProvider)
? empty
: ChatsList(onSelected: widget.onSelected),
],
searchTerms(context),
Expanded(
child: ref.watch(isGuestProvider)
? empty
: ChatsList(
onSelected: (roomId) {
ref
.read(roomListFilterProvider.notifier)
.updateSearchTerm(null);
setState(() => _isSearchVisible = false);
widget.onSelected(roomId);
},
),
),
],
),
),
);
}
Expand Down Expand Up @@ -256,10 +261,8 @@ class RoomsListWidgetState extends ConsumerState<RoomsListWidget> {
}

Widget get empty {
return SliverToBoxAdapter(
child: Center(
child: SvgPicture.asset('assets/images/empty_messages.svg'),
),
return Center(
child: SvgPicture.asset('assets/images/empty_messages.svg'),
);
}
}
19 changes: 13 additions & 6 deletions app/test/features/chat/chat_listing_search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ void main() {
find.byKey(ActerSearchWidget.searchBarKey),
findsOneWidget,
);
await tester.enterText(find.byKey(ActerSearchWidget.searchBarKey), 'CD');
await tester.enterText(
find.byKey(ActerSearchWidget.searchBarKey),
'CD',
);
await tester.pumpProviderScope(times: 2);
// -- we only see subset
expect(
Expand All @@ -119,7 +122,8 @@ void main() {
),
findsExactly(2),
);

await tester
.tap(find.byKey(ActerSearchWidget.clearSearchActionButtonKey));
await tester.enterText(find.byKey(ActerSearchWidget.searchBarKey), 'E');
await tester.pumpProviderScope(times: 2);
// -- we only see subset
Expand Down Expand Up @@ -190,7 +194,8 @@ void main() {
findsOneWidget,
);
await tester.enterText(
find.byKey(ActerSearchWidget.searchBarKey), 'mA', // part of one room ID
find.byKey(ActerSearchWidget.searchBarKey),
'mA', // part of one room ID
);
await tester.pumpProviderScope(times: 2);
// -- we only see subset
Expand All @@ -206,9 +211,11 @@ void main() {
find.text('Room ABC'),
findsOne,
);

await tester
.tap(find.byKey(ActerSearchWidget.clearSearchActionButtonKey));
await tester.enterText(
find.byKey(ActerSearchWidget.searchBarKey), 'mD', // part of one room ID
find.byKey(ActerSearchWidget.searchBarKey),
'mD', // part of one room ID
);
await tester.pumpProviderScope(times: 2);
// -- we only see subset
Expand All @@ -231,7 +238,7 @@ void main() {
// and we close
await tester
.tap(find.byKey(RoomsListWidget.closeSearchActionButtonKey));
await tester.pumpProviderScope(times: 1);
await tester.pumpProviderScope(times: 2);
// -- we should see all of them again
expect(
find.byType(
Expand Down

0 comments on commit 229ca1f

Please sign in to comment.