2020-09-08 21:08:50 +02:00
|
|
|
import 'package:esys_flutter_share/esys_flutter_share.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
|
|
|
|
|
|
|
import '../widgets/user_profile.dart';
|
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Page showing posts, comments, and general info about a user.
|
2020-09-08 21:08:50 +02:00
|
|
|
class UserPage extends HookWidget {
|
|
|
|
final int userId;
|
2020-12-31 14:58:23 +01:00
|
|
|
final String instanceHost;
|
2020-09-30 23:43:21 +02:00
|
|
|
final Future<UserDetails> _userDetails;
|
2020-09-08 21:08:50 +02:00
|
|
|
|
2020-12-31 14:58:23 +01:00
|
|
|
UserPage({@required this.userId, @required this.instanceHost})
|
2020-09-08 21:08:50 +02:00
|
|
|
: assert(userId != null),
|
2020-12-31 14:58:23 +01:00
|
|
|
assert(instanceHost != null),
|
|
|
|
_userDetails = LemmyApi(instanceHost).v1.getUserDetails(
|
2020-09-30 23:43:21 +02:00
|
|
|
userId: userId, savedOnly: true, sort: SortType.active);
|
|
|
|
|
2020-12-31 14:58:23 +01:00
|
|
|
UserPage.fromName({@required this.instanceHost, @required String username})
|
|
|
|
: assert(instanceHost != null),
|
2020-09-12 00:26:54 +02:00
|
|
|
assert(username != null),
|
|
|
|
userId = null,
|
2020-12-31 14:58:23 +01:00
|
|
|
_userDetails = LemmyApi(instanceHost).v1.getUserDetails(
|
2020-09-30 23:43:21 +02:00
|
|
|
username: username, savedOnly: true, sort: SortType.active);
|
2020-09-08 21:08:50 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-30 23:43:21 +02:00
|
|
|
final userDetailsSnap = useFuture(_userDetails);
|
2020-09-08 21:08:50 +02:00
|
|
|
|
2020-09-16 23:22:04 +02:00
|
|
|
final body = () {
|
2020-09-30 23:43:21 +02:00
|
|
|
if (userDetailsSnap.hasData) {
|
|
|
|
return UserProfile.fromUserDetails(userDetailsSnap.data);
|
|
|
|
} else if (userDetailsSnap.hasError) {
|
2021-01-03 19:43:39 +01:00
|
|
|
return const Center(child: Text('Could not find that user.'));
|
2020-09-08 22:56:45 +02:00
|
|
|
} else {
|
2021-01-03 19:43:39 +01:00
|
|
|
return const Center(child: CircularProgressIndicator());
|
2020-09-08 22:56:45 +02:00
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
2020-09-08 21:08:50 +02:00
|
|
|
return Scaffold(
|
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
actions: [
|
2020-09-30 23:43:21 +02:00
|
|
|
if (userDetailsSnap.hasData) ...[
|
2020-09-08 21:08:50 +02:00
|
|
|
IconButton(
|
2021-01-03 19:43:39 +01:00
|
|
|
icon: const Icon(Icons.email),
|
2020-09-08 21:08:50 +02:00
|
|
|
onPressed: () {}, // TODO: go to messaging page
|
|
|
|
),
|
|
|
|
IconButton(
|
2021-01-03 19:43:39 +01:00
|
|
|
icon: const Icon(Icons.share),
|
2020-09-30 23:43:21 +02:00
|
|
|
onPressed: () => Share.text('Share user',
|
|
|
|
userDetailsSnap.data.user.actorId, 'text/plain'),
|
2020-09-08 21:08:50 +02:00
|
|
|
)
|
|
|
|
]
|
|
|
|
],
|
|
|
|
),
|
2020-09-08 22:56:45 +02:00
|
|
|
body: body,
|
2020-09-08 21:08:50 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|