2024-06-03 15:36:46 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
2024-07-13 11:09:04 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2024-06-03 15:36:46 +00:00
|
|
|
import 'package:solian/models/account.dart';
|
2024-06-26 16:31:03 +00:00
|
|
|
import 'package:solian/models/account_status.dart';
|
2024-06-03 15:59:58 +00:00
|
|
|
import 'package:solian/platform.dart';
|
2024-06-26 17:33:03 +00:00
|
|
|
import 'package:solian/providers/account_status.dart';
|
2024-06-03 15:36:46 +00:00
|
|
|
import 'package:solian/widgets/account/account_avatar.dart';
|
|
|
|
import 'package:solian/widgets/account/account_badge.dart';
|
2024-06-26 16:31:03 +00:00
|
|
|
import 'package:solian/widgets/account/account_status_action.dart';
|
2024-06-27 03:04:06 +00:00
|
|
|
import 'package:timeago/timeago.dart';
|
2024-06-03 15:36:46 +00:00
|
|
|
|
|
|
|
class AccountHeadingWidget extends StatelessWidget {
|
|
|
|
final dynamic avatar;
|
|
|
|
final dynamic banner;
|
|
|
|
final String name;
|
|
|
|
final String nick;
|
|
|
|
final String? desc;
|
2024-07-13 11:09:04 +00:00
|
|
|
final Account? detail;
|
2024-06-03 15:36:46 +00:00
|
|
|
final List<AccountBadge>? badges;
|
|
|
|
|
2024-06-26 16:31:03 +00:00
|
|
|
final Future<Response>? status;
|
|
|
|
final Function? onEditStatus;
|
|
|
|
|
2024-06-03 15:36:46 +00:00
|
|
|
const AccountHeadingWidget({
|
|
|
|
super.key,
|
|
|
|
this.avatar,
|
|
|
|
this.banner,
|
|
|
|
required this.name,
|
|
|
|
required this.nick,
|
|
|
|
required this.desc,
|
|
|
|
required this.badges,
|
2024-07-13 11:09:04 +00:00
|
|
|
this.detail,
|
2024-06-26 16:31:03 +00:00
|
|
|
this.status,
|
|
|
|
this.onEditStatus,
|
2024-06-03 15:36:46 +00:00
|
|
|
});
|
|
|
|
|
2024-06-27 03:44:27 +00:00
|
|
|
void showStatusAction(BuildContext context, Status? current) {
|
2024-06-26 17:33:03 +00:00
|
|
|
if (onEditStatus == null) return;
|
|
|
|
|
2024-06-26 16:31:03 +00:00
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
2024-06-27 03:44:27 +00:00
|
|
|
builder: (context) => AccountStatusAction(currentStatus: current),
|
2024-06-26 17:33:03 +00:00
|
|
|
).then((val) {
|
2024-06-27 03:04:06 +00:00
|
|
|
if (val == true) onEditStatus!();
|
2024-06-26 17:33:03 +00:00
|
|
|
});
|
2024-06-26 16:31:03 +00:00
|
|
|
}
|
|
|
|
|
2024-06-03 15:36:46 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Stack(
|
|
|
|
clipBehavior: Clip.none,
|
|
|
|
children: [
|
|
|
|
ClipRRect(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(16)),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 16 / 7,
|
|
|
|
child: Container(
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainer,
|
|
|
|
child: banner != null
|
|
|
|
? AccountProfileImage(
|
|
|
|
content: banner,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
)
|
|
|
|
: const SizedBox(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).paddingSymmetric(horizontal: 16),
|
|
|
|
Positioned(
|
|
|
|
bottom: -30,
|
|
|
|
left: 32,
|
|
|
|
child: AccountAvatar(content: avatar, radius: 40),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-06-26 16:31:03 +00:00
|
|
|
Column(
|
2024-06-03 15:36:46 +00:00
|
|
|
children: [
|
2024-06-26 16:31:03 +00:00
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
|
|
textBaseline: TextBaseline.alphabetic,
|
|
|
|
children: [
|
2024-06-30 09:43:36 +00:00
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
nick,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
).paddingOnly(right: 4),
|
|
|
|
),
|
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
'@$name',
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 15,
|
|
|
|
),
|
2024-06-26 16:31:03 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-06-03 15:36:46 +00:00
|
|
|
),
|
2024-06-26 16:31:03 +00:00
|
|
|
if (status != null)
|
|
|
|
SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: FutureBuilder(
|
|
|
|
future: status,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData || snapshot.data!.body == null) {
|
|
|
|
return Text('loading'.tr);
|
|
|
|
}
|
|
|
|
|
2024-06-27 03:04:06 +00:00
|
|
|
final status = AccountStatus.fromJson(
|
|
|
|
snapshot.data!.body,
|
2024-06-26 16:31:03 +00:00
|
|
|
);
|
2024-06-27 03:04:06 +00:00
|
|
|
final info = StatusProvider.determineStatus(status);
|
2024-06-26 16:31:03 +00:00
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2024-07-12 05:15:46 +00:00
|
|
|
Text(info.$3),
|
2024-06-27 03:04:06 +00:00
|
|
|
if (!status.isOnline && status.lastSeenAt != null)
|
|
|
|
Opacity(
|
|
|
|
opacity: 0.75,
|
|
|
|
child: Text('accountLastSeenAt'.trParams({
|
|
|
|
'date': format(status.lastSeenAt!.toLocal(),
|
|
|
|
locale: 'en_short')
|
|
|
|
})).paddingOnly(left: 4),
|
|
|
|
),
|
2024-06-26 16:31:03 +00:00
|
|
|
info.$1.paddingSymmetric(horizontal: 6),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
onTap: () {
|
2024-06-27 03:44:27 +00:00
|
|
|
showStatusAction(context, status.status);
|
2024-06-26 16:31:03 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2024-06-03 15:36:46 +00:00
|
|
|
],
|
|
|
|
).paddingOnly(left: 116, top: 6),
|
|
|
|
const SizedBox(height: 4),
|
2024-07-13 11:09:04 +00:00
|
|
|
if (detail?.suspendedAt != null)
|
|
|
|
SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: Card(
|
|
|
|
child: ListTile(
|
|
|
|
title: Text('accountSuspended'.tr),
|
|
|
|
subtitle: Text('accountSuspendedAt'.trParams({
|
|
|
|
'date': DateFormat('y/M/d').format(detail!.suspendedAt!),
|
|
|
|
})),
|
|
|
|
trailing: const Icon(Icons.block),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).paddingOnly(left: 16, right: 16),
|
2024-06-03 15:36:46 +00:00
|
|
|
if (badges?.isNotEmpty ?? false)
|
|
|
|
SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: Card(
|
|
|
|
child: Wrap(
|
|
|
|
runSpacing: 2,
|
|
|
|
spacing: 4,
|
|
|
|
children: badges!.map((e) {
|
|
|
|
return AccountBadgeWidget(item: e);
|
|
|
|
}).toList(),
|
2024-06-03 15:59:58 +00:00
|
|
|
).paddingSymmetric(
|
|
|
|
horizontal: 8,
|
|
|
|
vertical: PlatformInfo.isMobile ? 0 : 6,
|
|
|
|
),
|
2024-06-03 15:36:46 +00:00
|
|
|
),
|
|
|
|
).paddingOnly(left: 16, right: 16),
|
|
|
|
SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: Card(
|
|
|
|
child: ListTile(
|
|
|
|
title: Text('description'.tr),
|
|
|
|
subtitle: Text(
|
|
|
|
(desc?.isNotEmpty ?? false) ? desc! : 'No description yet.',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).paddingOnly(left: 16, right: 16),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|