make communitity preview universal

This commit is contained in:
krawieck 2021-01-08 18:07:58 +01:00
parent 2c8d601d27
commit 5feee4c8b8
2 changed files with 42 additions and 37 deletions

View File

@ -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),
);
}

View File

@ -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),