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

76 lines
2.3 KiB
Dart
Raw Normal View History

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
2021-01-24 20:01:55 +01:00
import 'package:lemmy_api_client/v2.dart';
2021-01-27 20:50:28 +01:00
import '../util/extensions/api.dart';
2021-01-08 18:19:24 +01:00
import '../util/goto.dart';
import '../widgets/markdown_text.dart';
2020-09-30 19:05:00 +02:00
/// Infinite list of Users fetched by the given fetcher
class UsersListPage extends StatelessWidget {
final String title;
2021-01-24 20:01:55 +01:00
final List<UserViewSafe> users;
const UsersListPage({Key key, @required this.users, this.title})
: assert(users != null),
super(key: key);
@override
Widget build(BuildContext context) {
2020-09-08 23:16:30 +02:00
final theme = Theme.of(context);
2020-09-30 19:05:00 +02:00
// TODO: change to infinite scroll
return Scaffold(
2021-01-31 14:38:47 +01:00
appBar: AppBar(
title: Text(title ?? '', style: theme.textTheme.headline6),
centerTitle: true,
backgroundColor: theme.cardColor,
iconTheme: theme.iconTheme,
),
body: ListView.builder(
itemBuilder: (context, i) => UsersListItem(user: users[i]),
itemCount: users.length,
),
);
}
}
2021-01-08 18:19:24 +01:00
class UsersListItem extends StatelessWidget {
2021-01-24 20:01:55 +01:00
final UserViewSafe user;
2021-01-08 18:19:24 +01:00
const UsersListItem({Key key, @required this.user})
: assert(user != null),
super(key: key);
2021-01-08 18:19:24 +01:00
@override
Widget build(BuildContext context) => ListTile(
2021-01-31 14:38:47 +01:00
title: Text(user.user.originDisplayName),
2021-01-24 20:01:55 +01:00
subtitle: user.user.bio != null
2021-01-08 18:19:24 +01:00
? Opacity(
opacity: 0.5,
child: MarkdownText(
2021-01-24 20:01:55 +01:00
user.user.bio,
2021-01-08 18:19:24 +01:00
instanceHost: user.instanceHost,
),
)
: null,
2021-01-24 20:01:55 +01:00
onTap: () => goToUser.byId(context, user.instanceHost, user.user.id),
leading: user.user.avatar != null
2021-01-08 18:19:24 +01:00
? CachedNetworkImage(
height: 50,
width: 50,
2021-01-24 20:01:55 +01:00
imageUrl: user.user.avatar,
2021-01-08 18:19:24 +01:00
errorWidget: (_, __, ___) =>
const SizedBox(height: 50, width: 50),
imageBuilder: (context, imageProvider) => Container(
2021-01-31 14:38:47 +01:00
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover, image: imageProvider),
),
),
)
2021-01-08 18:19:24 +01:00
: const SizedBox(width: 50),
);
}