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

75 lines
2.5 KiB
Dart
Raw Normal View History

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';
import '../util/extensions/api.dart';
import '../util/goto.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(
brightness: theme.brightness,
2020-09-29 21:00:50 +02:00
title: Text(title, style: theme.textTheme.headline6),
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
}