diff --git a/lib/pages/communities_list.dart b/lib/pages/communities_list.dart index 3fa730c..a249443 100644 --- a/lib/pages/communities_list.dart +++ b/lib/pages/communities_list.dart @@ -36,38 +36,49 @@ class CommunitiesListPage extends StatelessWidget { builder: (community) => Column( children: [ const Divider(), - ListTile( - title: Text(community.name), - subtitle: community.description != null - ? Opacity( - opacity: 0.5, - child: MarkdownText( - community.description, - instanceHost: community.instanceHost, - ), - ) - : null, - onTap: () => goToCommunity.byId( - context, community.instanceHost, community.id), - leading: community.icon != null - ? CachedNetworkImage( - height: 50, - width: 50, - imageUrl: community.icon, - imageBuilder: (context, imageProvider) => Container( - decoration: BoxDecoration( - shape: BoxShape.circle, - image: DecorationImage( - fit: BoxFit.cover, image: imageProvider), - ), - ), - errorWidget: (_, __, ___) => const SizedBox(width: 50), - ) - : const SizedBox(width: 50), - ), + CommunitiesListItem( + community: community, + ) ], ), ), ); } } + +class CommunitiesListItem extends StatelessWidget { + final CommunityView community; + + const CommunitiesListItem({Key key, this.community}) : super(key: key); + + @override + Widget build(BuildContext context) => ListTile( + title: Text(community.name), + subtitle: community.description != null + ? Opacity( + opacity: 0.7, + child: MarkdownText( + community.description, + instanceHost: community.instanceHost, + ), + ) + : null, + onTap: () => + goToCommunity.byId(context, community.instanceHost, community.id), + leading: community.icon != null + ? CachedNetworkImage( + height: 50, + width: 50, + imageUrl: community.icon, + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + shape: BoxShape.circle, + image: DecorationImage( + fit: BoxFit.cover, image: imageProvider), + ), + ), + errorWidget: (_, __, ___) => const SizedBox(width: 50), + ) + : const SizedBox(width: 50), + ); +} diff --git a/lib/pages/search_results.dart b/lib/pages/search_results.dart index e478552..f5e6367 100644 --- a/lib/pages/search_results.dart +++ b/lib/pages/search_results.dart @@ -8,6 +8,7 @@ import '../util/goto.dart'; import '../widgets/comment.dart'; import '../widgets/post.dart'; import '../widgets/sortable_infinite_list.dart'; +import 'communities_list.dart'; class SearchResultsPage extends HookWidget { final String instance; @@ -105,14 +106,7 @@ class _SearchResultsList extends HookWidget { postCreatorId: null, ); case SearchType.communities: - // TODO: extract to universal widget - return ListTile( - title: Text((data as CommunityView).name), - onTap: () => goToCommunity.byId( - context, - instance, - (data as CommunityView).id, - )); + return CommunitiesListItem(community: data as CommunityView); case SearchType.posts: return Padding( padding: const EdgeInsets.only(bottom: 20),