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

56 lines
1.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2021-04-05 20:14:39 +02:00
import 'package:lemmy_api_client/v3.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';
2021-02-18 09:19:00 +01:00
import '../widgets/avatar.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-04-05 20:14:39 +02:00
final List<PersonViewSafe> users;
const UsersListPage({Key? key, required this.users, this.title = ''})
: 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(
backgroundColor: theme.cardColor,
title: Text(title),
2021-01-31 14:38:47 +01:00
),
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-04-05 20:14:39 +02:00
final PersonViewSafe user;
2021-01-08 18:19:24 +01:00
const UsersListItem({Key? key, required this.user}) : super(key: key);
2021-01-08 18:19:24 +01:00
@override
Widget build(BuildContext context) => ListTile(
2021-04-27 21:59:04 +02:00
title: Text(user.person.originPresentName),
2021-04-05 20:14:39 +02:00
subtitle: user.person.bio != null
2021-01-08 18:19:24 +01:00
? Opacity(
opacity: 0.5,
child: MarkdownText(
user.person.bio!,
2021-01-08 18:19:24 +01:00
instanceHost: user.instanceHost,
),
)
: null,
2021-04-05 20:14:39 +02:00
onTap: () => goToUser.fromPersonSafe(context, user.person),
leading: Avatar(url: user.person.avatar),
2021-01-08 18:19:24 +01:00
);
}