diff --git a/lib/pages/chat_details/chat_details.dart b/lib/pages/chat_details/chat_details.dart index 8dcb722606..f43a720d35 100644 --- a/lib/pages/chat_details/chat_details.dart +++ b/lib/pages/chat_details/chat_details.dart @@ -125,7 +125,7 @@ class ChatDetailsController extends State searchFunc: (event) => event.isContainsLink, limit: _linksFetchLimit, ); - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + WidgetsBinding.instance.addPostFrameCallback((_) { nestedScrollViewState.currentState!.innerController.addListener( _listenerInnerController, ); @@ -143,8 +143,10 @@ class ChatDetailsController extends State } void _listenerInnerController() { - Logs().d("ChatDetails::currentTab - ${tabController!.index}"); - if (nestedScrollViewState.currentState!.innerController.shouldLoadMore) { + Logs().d("ChatDetails::currentTab - ${tabController?.index}"); + if (nestedScrollViewState.currentState?.innerController.shouldLoadMore == + true && + tabController?.index != null) { switch (chatDetailsPageView[tabController!.index]) { case ChatDetailsPage.media: mediaListController?.loadMore(); @@ -532,7 +534,8 @@ class ChatDetailsController extends State key: const PageStorageKey("members"), members: members ?? [], actualMembersCount: actualMembersCount, - canRequestMoreMembers: members!.length < actualMembersCount, + canRequestMoreMembers: + (members?.length ?? 0) < actualMembersCount, requestMoreMembersAction: requestMoreMembersAction, openDialogInvite: openDialogInvite, isMobileAndTablet: isMobileAndTablet, diff --git a/lib/pages/chat_details/chat_details_page_view/links/chat_details_links_page.dart b/lib/pages/chat_details/chat_details_page_view/links/chat_details_links_page.dart index 6c09bdef69..f8c49d4328 100644 --- a/lib/pages/chat_details/chat_details_page_view/links/chat_details_links_page.dart +++ b/lib/pages/chat_details/chat_details_page_view/links/chat_details_links_page.dart @@ -1,28 +1,24 @@ import 'package:fluffychat/app_state/success.dart'; import 'package:fluffychat/domain/app_state/room/timeline_search_event_state.dart'; -import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; import 'package:fluffychat/pages/chat_details/chat_details_page_view/links/chat_details_links_item.dart'; +import 'package:fluffychat/presentation/same_type_events_builder/same_type_events_builder.dart'; import 'package:flutter/material.dart'; -import 'package:matrix/matrix.dart'; -import 'package:fluffychat/pages/chat_details/chat_details_page_view/same_type_events_list_controller.dart'; +import 'package:fluffychat/presentation/same_type_events_builder/same_type_events_controller.dart'; class ChatDetailsLinksPage extends StatelessWidget { - static const _linksFetchLimit = 20; - final Future Function() getTimeline; + final SameTypeEventsBuilderController controller; const ChatDetailsLinksPage({ Key? key, - required this.getTimeline, + required this.controller, }) : super(key: key); @override Widget build(BuildContext context) { - return SameTypeEventsListBuilder( - getTimeline: getTimeline, - searchFunc: (event) => event.isContainsLink, - limit: _linksFetchLimit, - builder: (context, eventsState) { + return SameTypeEventsBuilder( + controller: controller, + builder: (context, eventsState, _) { final events = eventsState .getSuccessOrNull() ?.events ?? diff --git a/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart b/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart index e8c37b9c68..2e63fa9925 100644 --- a/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart +++ b/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart @@ -2,7 +2,9 @@ import 'package:fluffychat/app_state/success.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/domain/app_state/room/timeline_search_event_state.dart'; import 'package:fluffychat/pages/chat/events/event_video_player.dart'; -import 'package:fluffychat/pages/chat_details/chat_details_page_view/same_type_events_list_controller.dart'; +import 'package:fluffychat/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart'; +import 'package:fluffychat/presentation/same_type_events_builder/same_type_events_builder.dart'; +import 'package:fluffychat/presentation/same_type_events_builder/same_type_events_controller.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; import 'package:fluffychat/widgets/mxc_image.dart'; import 'package:flutter/material.dart'; @@ -10,33 +12,30 @@ import 'package:flutter_blurhash/flutter_blurhash.dart'; import 'package:matrix/matrix.dart'; class ChatDetailsMediaPage extends StatelessWidget { - static const _mediaFetchLimit = 20; - final Future Function() getTimeline; + final SameTypeEventsBuilderController controller; final Map? cacheMap; final DownloadVideoEventCallback handleDownloadVideoEvent; const ChatDetailsMediaPage({ Key? key, - required this.getTimeline, + required this.controller, required this.handleDownloadVideoEvent, this.cacheMap, }) : super(key: key); @override Widget build(BuildContext context) { - return SameTypeEventsListBuilder( - getTimeline: getTimeline, - searchFunc: (event) => event.isVideoOrImage, - limit: _mediaFetchLimit, - builder: (context, eventsState) { + return SameTypeEventsBuilder( + controller: controller, + builder: (context, eventsState, _) { final events = eventsState .getSuccessOrNull() ?.events ?? []; Logs().v("ChatDetailsMediaPage::events: ${events.length}"); return SliverGrid.builder( - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 3, + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: ChatDetailsMediaStyle.crossAxisCount(context), ), itemCount: events.length, itemBuilder: (context, index) => @@ -59,6 +58,7 @@ class ChatDetailsMediaPage extends StatelessWidget { class _ImageItem extends StatelessWidget { final Event event; final Map? cacheMap; + const _ImageItem({ required this.event, this.cacheMap, @@ -85,6 +85,7 @@ class _VideoItem extends StatelessWidget { final Event event; final DownloadVideoEventCallback handleDownloadVideoEvent; final Map? thumbnailCacheMap; + const _VideoItem({ required this.event, required this.handleDownloadVideoEvent, diff --git a/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart b/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart index 69420f948a..297d36a706 100644 --- a/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart +++ b/lib/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart @@ -1,11 +1,23 @@ +import 'package:fluffychat/di/global/get_it_initializer.dart'; +import 'package:fluffychat/utils/responsive/responsive_utils.dart'; import 'package:flutter/material.dart'; class ChatDetailsMediaStyle { + static ResponsiveUtils responsive = getIt.get(); + static const durationPadding = EdgeInsets.symmetric( horizontal: 4, vertical: 2, ); + static int crossAxisCount(BuildContext context) { + if (responsive.isWebDesktop(context)) { + return 5; + } else { + return 3; + } + } + static Decoration durationBoxDecoration(BuildContext context) => ShapeDecoration( color: Theme.of(context).colorScheme.onBackground.withOpacity(0.5), diff --git a/lib/pages/chat_details/chat_details_page_view/same_type_events_list_builder_view.dart b/lib/pages/chat_details/chat_details_page_view/same_type_events_list_builder_view.dart deleted file mode 100644 index 431948f51d..0000000000 --- a/lib/pages/chat_details/chat_details_page_view/same_type_events_list_builder_view.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'package:fluffychat/pages/chat_details/chat_details_page_view/same_type_events_list_controller.dart'; -import 'package:fluffychat/widgets/twake_components/twake_loading/center_loading_indicator.dart'; -import 'package:flutter/material.dart'; - -class SameTypeEventsListBuilderView extends StatelessWidget { - final SameTypeEventsBuilderController controller; - - const SameTypeEventsListBuilderView({ - Key? key, - required this.controller, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return RefreshIndicator( - onRefresh: controller.refresh, - child: CustomScrollView( - controller: controller.scrollController, - slivers: [ - ValueListenableBuilder( - valueListenable: controller.refreshing, - builder: (context, refreshing, child) => SliverToBoxAdapter( - child: refreshing - ? const CenterLoadingIndicator() - : const SizedBox(), - ), - ), - ValueListenableBuilder( - valueListenable: controller.eventsNotifier, - builder: (context, eventsState, child) => - controller.widget.builder(context, eventsState), - ), - ValueListenableBuilder( - valueListenable: controller.loadingMore, - builder: (context, loadingMore, child) => SliverToBoxAdapter( - child: loadingMore - ? const CenterLoadingIndicator() - : const SizedBox(), - ), - ), - ], - ), - ); - } -} diff --git a/lib/presentation/same_type_events_builder/same_type_events_list_builder.dart b/lib/presentation/same_type_events_builder/same_type_events_builder.dart similarity index 99% rename from lib/presentation/same_type_events_builder/same_type_events_list_builder.dart rename to lib/presentation/same_type_events_builder/same_type_events_builder.dart index 68ab5efe24..1cc9c70590 100644 --- a/lib/presentation/same_type_events_builder/same_type_events_list_builder.dart +++ b/lib/presentation/same_type_events_builder/same_type_events_builder.dart @@ -39,7 +39,7 @@ class SameTypeEventsBuilder extends StatelessWidget { child: loadingMore ? const CenterLoadingIndicator() : const SizedBox(), ), - ) + ), ], ); } diff --git a/pubspec.lock b/pubspec.lock index e2063abea5..530040128d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -934,7 +934,7 @@ packages: description: path: "." ref: master - resolved-ref: "eb0ac6c32cc3bdf33810c2f1440aa2e2e28418ee" + resolved-ref: eb0ac6c32cc3bdf33810c2f1440aa2e2e28418ee url: "https://github.com/linagora/flutter_matrix_html.git" source: git version: "1.2.0"