1
0
mirror of https://github.com/krawieck/lemmur/ synced 2024-12-16 10:30:24 +01:00
lemmur-app-android/lib/pages/user.dart

68 lines
2.1 KiB
Dart
Raw Normal View History

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';
class UserPage extends HookWidget {
final int userId;
final String instanceUrl;
final Future<UserView> _userView;
UserPage({@required this.userId, @required this.instanceUrl})
: assert(userId != null),
assert(instanceUrl != null),
_userView = LemmyApi(instanceUrl)
.v1
.getUserDetails(
userId: userId, savedOnly: true, sort: SortType.active)
.then((res) => res.user);
2020-09-12 17:03:00 +02:00
UserPage.fromName({@required this.instanceUrl, @required String username})
: assert(instanceUrl != null),
assert(username != null),
userId = null,
_userView = LemmyApi(instanceUrl)
.v1
.getUserDetails(
username: username, savedOnly: true, sort: SortType.active)
.then((res) => res.user);
2020-09-08 21:08:50 +02:00
@override
Widget build(BuildContext context) {
2020-09-16 23:22:04 +02:00
final userViewSnap = useFuture(_userView);
2020-09-08 21:08:50 +02:00
2020-09-16 23:22:04 +02:00
final body = () {
2020-09-08 22:56:45 +02:00
if (userViewSnap.hasData) {
return UserProfile.fromUserView(userViewSnap.data);
} else if (userViewSnap.hasError) {
return Center(child: Text('Could not find that user.'));
} else {
return Center(child: CircularProgressIndicator());
}
}();
2020-09-08 21:08:50 +02:00
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
actions: [
if (userViewSnap.hasData) ...[
IconButton(
2020-09-08 21:17:17 +02:00
icon: Icon(Icons.email),
2020-09-08 21:08:50 +02:00
onPressed: () {}, // TODO: go to messaging page
),
IconButton(
icon: Icon(Icons.share),
onPressed: () => Share.text(
'Share user', userViewSnap.data.actorId, 'text/plain'),
)
]
],
),
2020-09-08 22:56:45 +02:00
body: body,
2020-09-08 21:08:50 +02:00
);
}
}