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

70 lines
1.9 KiB
Dart
Raw Normal View History

2020-09-08 23:01:40 +02:00
import 'package:flutter/material.dart';
2021-01-24 20:01:55 +01:00
import 'package:lemmy_api_client/v2.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 Future<List<CommunityView>> Function(
int page,
int batchSize,
SortType sortType,
) fetcher;
2020-09-08 23:01:40 +02:00
2020-09-29 21:00:50 +02:00
const CommunitiesListPage({Key key, @required this.fetcher, this.title = ''})
: assert(fetcher != null),
2020-09-29 21:00:50 +02:00
assert(title != null),
2020-09-08 23:01:40 +02:00
super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
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
],
),
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;
const CommunitiesListItem({Key key, @required this.community})
: assert(community != null),
super(key: key);
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(
2021-01-24 20:01:55 +01:00
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
);
}