lemmur-app-android/lib/pages/communities_list.dart

67 lines
1.8 KiB
Dart
Raw Normal View History

2020-09-08 23:01:40 +02:00
import 'package:flutter/material.dart';
2021-04-05 20:14:39 +02:00
import 'package:lemmy_api_client/v3.dart';
2020-09-08 23:01:40 +02:00
import '../util/goto.dart';
2021-02-18 09:19:00 +01:00
import '../widgets/avatar.dart';
2020-09-08 23:01:40 +02:00
import '../widgets/markdown_text.dart';
import '../widgets/sortable_infinite_list.dart';
2020-09-08 23:01:40 +02:00
2020-09-30 19:05:00 +02:00
/// Infinite list of Communities fetched by the given fetcher
2020-09-08 23:01:40 +02:00
class CommunitiesListPage extends StatelessWidget {
final String title;
final FetcherWithSorting<CommunityView> fetcher;
2020-09-08 23:01:40 +02:00
2022-05-11 22:23:18 +02:00
const CommunitiesListPage({
super.key,
required this.fetcher,
this.title = '',
});
2020-09-08 23:01:40 +02:00
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
2020-09-08 23:01:40 +02:00
return Scaffold(
appBar: AppBar(
backgroundColor: theme.cardColor,
2021-02-09 15:12:13 +01:00
title: Text(title),
),
2020-09-29 11:13:17 +02:00
body: SortableInfiniteList<CommunityView>(
2020-09-29 11:11:43 +02:00
fetcher: fetcher,
2021-02-09 20:39:31 +01:00
itemBuilder: (community) => Column(
2020-09-29 11:11:43 +02:00
children: [
2021-01-03 19:43:39 +01:00
const Divider(),
2021-01-08 18:07:58 +01:00
CommunitiesListItem(
community: community,
)
2020-09-29 11:11:43 +02:00
],
),
2021-04-22 21:08:30 +02:00
uniqueProp: (item) => item.community.actorId,
2020-09-29 11:13:17 +02:00
),
);
}
2020-09-08 23:01:40 +02:00
}
2021-01-08 18:07:58 +01:00
class CommunitiesListItem extends StatelessWidget {
final CommunityView community;
2022-05-11 22:23:18 +02:00
const CommunitiesListItem({super.key, required this.community});
2021-01-08 18:07:58 +01:00
@override
Widget build(BuildContext context) => ListTile(
2021-01-24 20:01:55 +01:00
title: Text(community.community.name),
subtitle: community.community.description != null
2021-01-08 18:07:58 +01:00
? Opacity(
opacity: 0.7,
child: MarkdownText(
community.community.description!,
2021-01-08 18:07:58 +01:00
instanceHost: community.instanceHost,
),
)
: null,
2021-01-24 20:01:55 +01:00
onTap: () => goToCommunity.byId(
context, community.instanceHost, community.community.id),
2021-02-18 09:19:00 +01:00
leading: Avatar(url: community.community.icon),
2021-01-08 18:07:58 +01:00
);
}