Merge pull request #31 from krawieck/user-profile-page
This commit is contained in:
commit
8bd4218dd3
|
@ -0,0 +1,58 @@
|
|||
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);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var userViewSnap = useFuture(_userView);
|
||||
|
||||
var body = () {
|
||||
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());
|
||||
}
|
||||
}();
|
||||
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
shadowColor: Colors.transparent,
|
||||
actions: [
|
||||
if (userViewSnap.hasData) ...[
|
||||
IconButton(
|
||||
icon: Icon(Icons.email),
|
||||
onPressed: () {}, // TODO: go to messaging page
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.share),
|
||||
onPressed: () => Share.text(
|
||||
'Share user', userViewSnap.data.actorId, 'text/plain'),
|
||||
)
|
||||
]
|
||||
],
|
||||
),
|
||||
body: body,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -10,18 +10,21 @@ import '../util/text_color.dart';
|
|||
import 'badge.dart';
|
||||
|
||||
class UserProfile extends HookWidget {
|
||||
final int userId;
|
||||
final Future<UserView> _userView;
|
||||
final String instanceUrl;
|
||||
|
||||
// TODO: add `.fromUser` constructor
|
||||
UserProfile({@required this.userId, @required this.instanceUrl})
|
||||
UserProfile({@required int userId, @required this.instanceUrl})
|
||||
: _userView = LemmyApi(instanceUrl)
|
||||
.v1
|
||||
.getUserDetails(
|
||||
userId: userId, savedOnly: true, sort: SortType.active)
|
||||
.then((res) => res.user);
|
||||
|
||||
UserProfile.fromUserView(UserView userView)
|
||||
: _userView = Future.value(userView),
|
||||
instanceUrl = userView.actorId.split('/')[2];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var theme = Theme.of(context);
|
||||
|
|
Loading…
Reference in New Issue