2020-09-08 23:01:40 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
|
|
|
|
2020-09-19 00:40:47 +02:00
|
|
|
import '../util/extensions/api.dart';
|
2020-09-09 17:41:54 +02:00
|
|
|
import '../util/goto.dart';
|
2020-09-08 23:01:40 +02:00
|
|
|
import '../widgets/markdown_text.dart';
|
2020-09-29 12:24:52 +02:00
|
|
|
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;
|
2020-09-29 00:57:25 +02:00
|
|
|
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 = ''})
|
2020-09-29 00:57:25 +02:00
|
|
|
: 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(
|
2020-09-29 00:57:25 +02:00
|
|
|
appBar: AppBar(
|
2020-09-29 00:59:19 +02:00
|
|
|
brightness: theme.brightness,
|
2020-09-29 21:00:50 +02:00
|
|
|
title: Text(title, style: theme.textTheme.headline6),
|
2020-09-29 00:57:25 +02:00
|
|
|
centerTitle: true,
|
|
|
|
backgroundColor: theme.cardColor,
|
|
|
|
iconTheme: theme.iconTheme,
|
|
|
|
),
|
2020-09-29 11:13:17 +02:00
|
|
|
body: SortableInfiniteList<CommunityView>(
|
2020-09-29 11:11:43 +02:00
|
|
|
fetcher: fetcher,
|
|
|
|
builder: (community) => Column(
|
|
|
|
children: [
|
|
|
|
Divider(),
|
|
|
|
ListTile(
|
|
|
|
title: Text(community.name),
|
|
|
|
subtitle: community.description != null
|
|
|
|
? Opacity(
|
|
|
|
opacity: 0.5,
|
|
|
|
child: MarkdownText(
|
|
|
|
community.description,
|
|
|
|
instanceUrl: community.instanceUrl,
|
2020-09-09 11:32:34 +02:00
|
|
|
),
|
2020-09-29 11:11:43 +02:00
|
|
|
)
|
|
|
|
: null,
|
|
|
|
onTap: () => goToCommunity.byId(
|
|
|
|
context, community.instanceUrl, 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: (_, __, ___) => SizedBox(width: 50),
|
|
|
|
)
|
|
|
|
: SizedBox(width: 50),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-09-29 11:13:17 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-09-08 23:01:40 +02:00
|
|
|
}
|