2020-08-31 21:04:17 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2020-08-31 12:05:45 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
|
|
|
|
2020-09-09 17:41:54 +02:00
|
|
|
import '../util/api_extensions.dart';
|
|
|
|
import '../util/goto.dart';
|
2020-08-31 15:43:09 +02:00
|
|
|
import '../util/intl.dart';
|
2020-09-03 16:18:42 +02:00
|
|
|
import '../util/text_color.dart';
|
2020-09-01 21:59:00 +02:00
|
|
|
import 'badge.dart';
|
2020-08-31 15:43:09 +02:00
|
|
|
|
2020-08-31 12:05:45 +02:00
|
|
|
class UserProfile extends HookWidget {
|
|
|
|
final Future<UserView> _userView;
|
2020-09-01 11:55:22 +02:00
|
|
|
final String instanceUrl;
|
2020-08-31 12:05:45 +02:00
|
|
|
|
2020-09-04 11:08:11 +02:00
|
|
|
// TODO: add `.fromUser` constructor
|
2020-09-08 21:08:37 +02:00
|
|
|
UserProfile({@required int userId, @required this.instanceUrl})
|
2020-09-01 11:55:22 +02:00
|
|
|
: _userView = LemmyApi(instanceUrl)
|
2020-08-31 12:05:45 +02:00
|
|
|
.v1
|
2020-09-01 11:55:22 +02:00
|
|
|
.getUserDetails(
|
|
|
|
userId: userId, savedOnly: true, sort: SortType.active)
|
|
|
|
.then((res) => res.user);
|
2020-08-31 12:05:45 +02:00
|
|
|
|
2020-09-08 21:08:37 +02:00
|
|
|
UserProfile.fromUserView(UserView userView)
|
|
|
|
: _userView = Future.value(userView),
|
2020-09-09 17:41:54 +02:00
|
|
|
instanceUrl = userView.instanceUrl;
|
2020-09-08 21:08:37 +02:00
|
|
|
|
2020-08-31 12:05:45 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var theme = Theme.of(context);
|
2020-09-03 16:18:42 +02:00
|
|
|
final colorOnTopOfAccentColor =
|
|
|
|
textColorBasedOnBackground(theme.accentColor);
|
2020-08-31 12:05:45 +02:00
|
|
|
|
2020-09-01 21:36:58 +02:00
|
|
|
var userViewSnap = useFuture(_userView, preserveState: false);
|
2020-08-31 12:05:45 +02:00
|
|
|
|
2020-09-04 11:04:10 +02:00
|
|
|
Widget bio = () {
|
|
|
|
if (userViewSnap.hasData) {
|
|
|
|
if (userViewSnap.data.bio != null) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(10),
|
|
|
|
child: Text(userViewSnap.data.bio),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Center(
|
|
|
|
child: Text(
|
|
|
|
'no bio',
|
|
|
|
style: const TextStyle(fontStyle: FontStyle.italic),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-09-01 11:55:22 +02:00
|
|
|
} else {
|
2020-09-04 11:04:10 +02:00
|
|
|
return Center(child: CircularProgressIndicator());
|
2020-09-01 11:55:22 +02:00
|
|
|
}
|
2020-09-04 11:04:10 +02:00
|
|
|
}();
|
2020-09-01 11:55:22 +02:00
|
|
|
|
|
|
|
Widget tabs() => DefaultTabController(
|
2020-08-31 21:04:17 +02:00
|
|
|
length: 3,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
TabBar(
|
|
|
|
labelColor: theme.textTheme.bodyText1.color,
|
|
|
|
tabs: [
|
|
|
|
Tab(text: 'Posts'),
|
|
|
|
Tab(text: 'Comments'),
|
|
|
|
Tab(text: 'About'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TabBarView(
|
|
|
|
children: [
|
|
|
|
Center(
|
2020-09-01 11:55:22 +02:00
|
|
|
child: Text(
|
|
|
|
'Posts',
|
|
|
|
style: const TextStyle(fontSize: 36),
|
|
|
|
),
|
|
|
|
),
|
2020-08-31 21:04:17 +02:00
|
|
|
Center(
|
2020-09-01 11:55:22 +02:00
|
|
|
child: Text(
|
|
|
|
'Comments',
|
|
|
|
style: const TextStyle(fontSize: 36),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
bio,
|
2020-08-31 21:04:17 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2020-08-31 12:05:45 +02:00
|
|
|
return Center(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
2020-09-01 11:55:22 +02:00
|
|
|
if (userViewSnap.data?.banner != null)
|
2020-08-31 21:04:17 +02:00
|
|
|
CachedNetworkImage(
|
2020-09-01 11:55:22 +02:00
|
|
|
imageUrl: userViewSnap.data.banner,
|
2020-09-13 16:05:17 +02:00
|
|
|
errorWidget: (_, __, ___) => Container(),
|
2020-08-31 21:04:17 +02:00
|
|
|
)
|
|
|
|
else
|
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: double.infinity,
|
|
|
|
color: theme.primaryColor,
|
|
|
|
),
|
2020-09-03 22:10:22 +02:00
|
|
|
Container(
|
|
|
|
height: 200,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: LinearGradient(
|
|
|
|
begin: FractionalOffset.topCenter,
|
|
|
|
end: FractionalOffset.bottomCenter,
|
|
|
|
colors: [
|
|
|
|
Colors.black26,
|
|
|
|
Colors.transparent,
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-08-31 12:05:45 +02:00
|
|
|
SafeArea(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 60),
|
|
|
|
child: SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
height: double.infinity,
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
2020-09-01 11:55:22 +02:00
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topRight: Radius.circular(40),
|
|
|
|
topLeft: Radius.circular(40),
|
|
|
|
),
|
2020-08-31 12:05:45 +02:00
|
|
|
color: theme.scaffoldBackgroundColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SafeArea(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2020-09-01 11:55:22 +02:00
|
|
|
if (userViewSnap.data?.avatar != null)
|
2020-08-31 21:04:17 +02:00
|
|
|
SizedBox(
|
|
|
|
width: 80,
|
|
|
|
height: 80,
|
|
|
|
child: Container(
|
|
|
|
// clipBehavior: Clip.antiAlias,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(blurRadius: 6, color: Colors.black54)
|
|
|
|
],
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(15)),
|
|
|
|
border: Border.all(color: Colors.white, width: 3),
|
|
|
|
),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(12)),
|
|
|
|
child: CachedNetworkImage(
|
2020-09-01 11:55:22 +02:00
|
|
|
imageUrl: userViewSnap.data.avatar,
|
2020-09-13 16:05:17 +02:00
|
|
|
errorWidget: (_, __, ___) => Container(),
|
2020-08-31 21:04:17 +02:00
|
|
|
),
|
|
|
|
),
|
2020-08-31 12:05:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
2020-09-01 11:55:22 +02:00
|
|
|
padding: userViewSnap.data?.avatar != null
|
|
|
|
? const EdgeInsets.only(top: 8.0)
|
|
|
|
: const EdgeInsets.only(top: 70),
|
2020-09-03 23:35:13 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: userViewSnap.data?.avatar == null ? 10 : 0),
|
|
|
|
child: Text(
|
|
|
|
userViewSnap.data?.preferredUsername ??
|
|
|
|
userViewSnap.data?.name ??
|
|
|
|
'',
|
|
|
|
style: theme.textTheme.headline6,
|
|
|
|
),
|
2020-08-31 12:05:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 4.0),
|
2020-09-09 17:41:54 +02:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'@${userViewSnap.data?.name ?? ''}@',
|
|
|
|
style: theme.textTheme.caption,
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () => goToInstance(context, instanceUrl),
|
|
|
|
child: Text(
|
|
|
|
'$instanceUrl',
|
|
|
|
style: theme.textTheme.caption,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2020-08-31 12:05:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
2020-09-03 23:35:13 +02:00
|
|
|
padding: const EdgeInsets.only(top: 15),
|
2020-08-31 12:05:45 +02:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2020-09-01 21:59:00 +02:00
|
|
|
Badge(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.comment, // TODO: should be article icon
|
|
|
|
size: 15,
|
2020-09-03 16:18:42 +02:00
|
|
|
color: colorOnTopOfAccentColor,
|
2020-09-01 21:59:00 +02:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 4.0),
|
2020-09-03 16:18:42 +02:00
|
|
|
child: Text(
|
|
|
|
'''
|
|
|
|
${userViewSnap.hasData ? compactNumber(userViewSnap.data.numberOfPosts) : '-'} Post${pluralS(userViewSnap.data?.numberOfPosts ?? 0)}''',
|
|
|
|
style:
|
|
|
|
TextStyle(color: colorOnTopOfAccentColor),
|
|
|
|
),
|
2020-09-01 21:59:00 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-08-31 12:05:45 +02:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16.0),
|
2020-09-01 21:59:00 +02:00
|
|
|
child: Badge(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.comment,
|
|
|
|
size: 15,
|
2020-09-03 16:18:42 +02:00
|
|
|
color: colorOnTopOfAccentColor,
|
2020-09-01 21:59:00 +02:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 4.0),
|
2020-09-03 16:18:42 +02:00
|
|
|
child: Text(
|
|
|
|
'''
|
|
|
|
${userViewSnap.hasData ? compactNumber(userViewSnap.data.numberOfComments) : '-'} Comment${pluralS(userViewSnap.data?.numberOfComments ?? 0)}''',
|
|
|
|
style:
|
|
|
|
TextStyle(color: colorOnTopOfAccentColor),
|
|
|
|
),
|
2020-09-01 21:59:00 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-08-31 12:05:45 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
2020-09-03 23:35:13 +02:00
|
|
|
padding: const EdgeInsets.only(top: 15),
|
2020-08-31 12:05:45 +02:00
|
|
|
child: Text(
|
2020-09-01 11:55:22 +02:00
|
|
|
'''
|
|
|
|
Joined ${userViewSnap.hasData ? timeago.format(userViewSnap.data.published) : ''}''',
|
2020-08-31 12:05:45 +02:00
|
|
|
style: theme.textTheme.bodyText1,
|
|
|
|
),
|
|
|
|
),
|
2020-09-03 23:35:13 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 8),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.cake,
|
|
|
|
size: 13,
|
2020-08-31 12:05:45 +02:00
|
|
|
),
|
2020-09-03 23:35:13 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 4.0),
|
|
|
|
child: Text(
|
|
|
|
userViewSnap.hasData
|
|
|
|
? DateFormat('MMM dd, yyyy')
|
|
|
|
.format(userViewSnap.data.published)
|
|
|
|
: '',
|
|
|
|
style: theme.textTheme.bodyText1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-08-31 12:05:45 +02:00
|
|
|
),
|
2020-09-01 11:55:22 +02:00
|
|
|
Expanded(child: tabs())
|
2020-08-31 12:05:45 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-08-31 21:04:17 +02:00
|
|
|
}
|