✨ Badges
This commit is contained in:
@ -50,3 +50,58 @@ class AccountAvatar extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AccountProfileImage extends StatelessWidget {
|
||||
final dynamic content;
|
||||
final BoxFit fit;
|
||||
|
||||
const AccountProfileImage({
|
||||
super.key,
|
||||
required this.content,
|
||||
this.fit = BoxFit.cover,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool direct = false;
|
||||
bool isEmpty = content == null;
|
||||
if (content is String) {
|
||||
direct = content.startsWith('http');
|
||||
if (!isEmpty) isEmpty = content.isEmpty;
|
||||
if (!isEmpty) isEmpty = content.endsWith('/api/attachments/0');
|
||||
}
|
||||
|
||||
final url = direct
|
||||
? content
|
||||
: '${ServiceFinder.services['paperclip']}/api/attachments/$content';
|
||||
|
||||
if (PlatformInfo.canCacheImage) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: url,
|
||||
fit: fit,
|
||||
progressIndicatorBuilder: (context, url, downloadProgress) => Center(
|
||||
child: CircularProgressIndicator(
|
||||
value: downloadProgress.progress,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Image.network(
|
||||
url,
|
||||
fit: fit,
|
||||
loadingBuilder: (BuildContext context, Widget child,
|
||||
ImageChunkEvent? loadingProgress) {
|
||||
if (loadingProgress == null) return child;
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
value: loadingProgress.expectedTotalBytes != null
|
||||
? loadingProgress.cumulativeBytesLoaded /
|
||||
loadingProgress.expectedTotalBytes!
|
||||
: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
62
lib/widgets/account/account_badge.dart
Normal file
62
lib/widgets/account/account_badge.dart
Normal file
@ -0,0 +1,62 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:solian/models/account.dart';
|
||||
|
||||
class AccountBadgeWidget extends StatefulWidget {
|
||||
final AccountBadge item;
|
||||
|
||||
const AccountBadgeWidget({super.key, required this.item});
|
||||
|
||||
@override
|
||||
State<AccountBadgeWidget> createState() => _AccountBadgeWidgetState();
|
||||
}
|
||||
|
||||
class _AccountBadgeWidgetState extends State<AccountBadgeWidget> {
|
||||
final Map<String, (String, Widget)> badges = {
|
||||
'solsynth.staff': (
|
||||
'badgeSolsynthStaff'.tr,
|
||||
const FaIcon(
|
||||
FontAwesomeIcons.screwdriverWrench,
|
||||
size: 16,
|
||||
color: Colors.teal,
|
||||
),
|
||||
),
|
||||
'solar.originalCitizen': (
|
||||
'badgeSolarOriginalCitizen'.tr,
|
||||
const FaIcon(
|
||||
FontAwesomeIcons.tent,
|
||||
size: 16,
|
||||
color: Colors.orange,
|
||||
),
|
||||
),
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final spec = badges[widget.item.type];
|
||||
|
||||
if (spec == null) return const SizedBox();
|
||||
|
||||
return Tooltip(
|
||||
richMessage: TextSpan(
|
||||
children: [
|
||||
TextSpan(text: '${spec.$1}\n'),
|
||||
if (widget.item.metadata?['title'] != null)
|
||||
TextSpan(
|
||||
text: '${widget.item.metadata?['title']}\n',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
TextSpan(
|
||||
text: 'badgeGrantAt'.trParams(
|
||||
{'date': DateFormat.yMEd().format(widget.item.createdAt)}),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Chip(
|
||||
label: spec.$2,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
105
lib/widgets/account/account_heading.dart
Normal file
105
lib/widgets/account/account_heading.dart
Normal file
@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/models/account.dart';
|
||||
import 'package:solian/widgets/account/account_avatar.dart';
|
||||
import 'package:solian/widgets/account/account_badge.dart';
|
||||
|
||||
class AccountHeadingWidget extends StatelessWidget {
|
||||
final dynamic avatar;
|
||||
final dynamic banner;
|
||||
final String name;
|
||||
final String nick;
|
||||
final String? desc;
|
||||
final List<AccountBadge>? badges;
|
||||
|
||||
const AccountHeadingWidget({
|
||||
super.key,
|
||||
this.avatar,
|
||||
this.banner,
|
||||
required this.name,
|
||||
required this.nick,
|
||||
required this.desc,
|
||||
required this.badges,
|
||||
});
|
||||
|
||||
@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),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
children: [
|
||||
Text(
|
||||
nick,
|
||||
style: const TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
).paddingOnly(right: 4),
|
||||
Text(
|
||||
'@$name',
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
).paddingOnly(left: 116, top: 6),
|
||||
const SizedBox(height: 4),
|
||||
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(),
|
||||
).paddingSymmetric(horizontal: 8),
|
||||
),
|
||||
).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),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ import 'package:get/get.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
import 'package:solian/models/account.dart';
|
||||
import 'package:solian/services.dart';
|
||||
import 'package:solian/widgets/account/account_avatar.dart';
|
||||
import 'package:solian/widgets/account/account_heading.dart';
|
||||
|
||||
class AccountProfilePopup extends StatefulWidget {
|
||||
final Account account;
|
||||
@ -44,7 +44,7 @@ class _AccountProfilePopupState extends State<AccountProfilePopup> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isBusy) {
|
||||
if (_isBusy || _userinfo == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
@ -53,64 +53,14 @@ class _AccountProfilePopupState extends State<AccountProfilePopup> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 16 / 7,
|
||||
child: Container(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
if (_userinfo!.banner != null)
|
||||
Image.network(
|
||||
'${ServiceFinder.services['paperclip']}/api/attachments/${_userinfo!.banner}',
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
Positioned(
|
||||
bottom: -30,
|
||||
left: 18,
|
||||
child: AccountAvatar(
|
||||
content: widget.account.banner,
|
||||
radius: 48,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
).paddingOnly(top: 32),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
children: [
|
||||
Text(
|
||||
_userinfo!.nick,
|
||||
style: const TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
).paddingOnly(right: 4),
|
||||
Text(
|
||||
'@${_userinfo!.name}',
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
).paddingOnly(left: 120, top: 8),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Card(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
child: ListTile(
|
||||
title: Text('description'.tr),
|
||||
subtitle: Text(
|
||||
_userinfo!.description.isNotEmpty
|
||||
? widget.account.description
|
||||
: 'No description yet.',
|
||||
),
|
||||
),
|
||||
),
|
||||
).paddingOnly(left: 24, right: 24, top: 8),
|
||||
AccountHeadingWidget(
|
||||
avatar: _userinfo!.avatar,
|
||||
banner: _userinfo!.banner,
|
||||
name: _userinfo!.name,
|
||||
nick: _userinfo!.nick,
|
||||
desc: _userinfo!.description,
|
||||
badges: _userinfo!.badges,
|
||||
).paddingOnly(top: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -65,6 +65,7 @@ class _AttachmentItemState extends State<AttachmentItem> {
|
||||
children: [
|
||||
if (PlatformInfo.canCacheImage)
|
||||
CachedNetworkImage(
|
||||
fit: widget.fit,
|
||||
imageUrl:
|
||||
'${ServiceFinder.services['paperclip']}/api/attachments/${widget.item.id}',
|
||||
progressIndicatorBuilder: (context, url, downloadProgress) =>
|
||||
@ -73,7 +74,6 @@ class _AttachmentItemState extends State<AttachmentItem> {
|
||||
value: downloadProgress.progress,
|
||||
),
|
||||
),
|
||||
fit: widget.fit,
|
||||
)
|
||||
else
|
||||
Image.network(
|
||||
|
@ -165,9 +165,11 @@ class _PostItemState extends State<PostItem> {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
AccountProfilePopup(account: item.author),
|
||||
builder: (context) => AccountProfilePopup(
|
||||
account: item.author,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
Reference in New Issue
Block a user