2020-09-08 20:24:36 +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 '../widgets/markdown_text.dart';
|
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Infinite list of Users fetched by the given fetcher
|
2020-09-08 20:24:36 +02:00
|
|
|
class UsersListPage extends StatelessWidget {
|
|
|
|
final String title;
|
|
|
|
final List<UserView> users;
|
|
|
|
|
|
|
|
const UsersListPage({Key key, @required this.users, this.title})
|
|
|
|
: assert(users != null),
|
|
|
|
super(key: key);
|
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
// TODO: go to user
|
2020-09-08 20:24:36 +02:00
|
|
|
void goToUser(BuildContext context, int id) {
|
|
|
|
print('GO TO USER $id');
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2020-09-08 20:24:36 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2020-09-08 23:16:30 +02:00
|
|
|
title: Text(title ?? '', style: theme.textTheme.headline6),
|
2020-09-08 20:24:36 +02:00
|
|
|
centerTitle: true,
|
2020-09-08 23:16:30 +02:00
|
|
|
backgroundColor: theme.cardColor,
|
|
|
|
iconTheme: theme.iconTheme,
|
2020-09-08 20:24:36 +02:00
|
|
|
),
|
|
|
|
body: ListView.builder(
|
|
|
|
itemBuilder: (context, i) => ListTile(
|
2020-09-09 11:19:12 +02:00
|
|
|
title: Text((users[i].preferredUsername == null ||
|
|
|
|
users[i].preferredUsername.isEmpty)
|
|
|
|
? '@${users[i].name}'
|
|
|
|
: users[i].preferredUsername),
|
2020-09-08 23:16:30 +02:00
|
|
|
subtitle: users[i].bio != null
|
|
|
|
? Opacity(
|
|
|
|
opacity: 0.5,
|
2020-09-12 09:30:22 +02:00
|
|
|
child: MarkdownText(
|
|
|
|
users[i].bio,
|
2020-12-31 14:58:23 +01:00
|
|
|
instanceHost: users[i].instanceHost,
|
2020-09-12 09:30:22 +02:00
|
|
|
),
|
2020-09-08 23:16:30 +02:00
|
|
|
)
|
|
|
|
: null,
|
2020-09-08 20:24:36 +02:00
|
|
|
onTap: () => goToUser(context, users[i].id),
|
|
|
|
leading: users[i].avatar != null
|
|
|
|
? CachedNetworkImage(
|
|
|
|
height: 50,
|
|
|
|
width: 50,
|
|
|
|
imageUrl: users[i].avatar,
|
2020-09-13 16:05:17 +02:00
|
|
|
errorWidget: (_, __, ___) =>
|
|
|
|
SizedBox(height: 50, width: 50),
|
2020-09-08 20:24:36 +02:00
|
|
|
imageBuilder: (context, imageProvider) => Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
image: DecorationImage(
|
|
|
|
fit: BoxFit.cover, image: imageProvider),
|
|
|
|
),
|
|
|
|
))
|
|
|
|
: SizedBox(width: 50),
|
|
|
|
),
|
|
|
|
itemCount: users.length,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|