💄 Optimize attachment list

This commit is contained in:
LittleSheep 2025-01-01 17:57:41 +08:00
parent a3c8dafff9
commit f614da7918
5 changed files with 205 additions and 203 deletions

View File

@ -281,11 +281,7 @@ class _ChatRoomScreenState extends State<ChatRoomScreen> {
Expanded(
child: InfiniteList(
reverse: true,
padding: const EdgeInsets.only(
left: 12,
right: 12,
top: 12,
),
padding: const EdgeInsets.only(top: 12),
hasReachedMax: _messageController.isAllLoaded,
itemCount: _messageController.messages.length,
isLoading: _messageController.isLoading,
@ -311,8 +307,6 @@ class _ChatRoomScreenState extends State<ChatRoomScreen> {
return Align(
alignment: Alignment.centerLeft,
child: Container(
constraints: BoxConstraints(maxWidth: 480),
child: ChatMessage(
data: message,
isMerged: canMerge,
@ -328,7 +322,6 @@ class _ChatRoomScreenState extends State<ChatRoomScreen> {
_inputGlobalKey.currentState?.deleteMessage(value);
},
),
),
);
},
),

View File

@ -153,9 +153,14 @@ class _HomeDashUpdateWidget extends StatelessWidget {
}
}
class _HomeDashSpecialDayWidget extends StatelessWidget {
class _HomeDashSpecialDayWidget extends StatefulWidget {
const _HomeDashSpecialDayWidget();
@override
State<_HomeDashSpecialDayWidget> createState() => _HomeDashSpecialDayWidgetState();
}
class _HomeDashSpecialDayWidgetState extends State<_HomeDashSpecialDayWidget> {
@override
Widget build(BuildContext context) {
final ua = context.watch<UserProvider>();
@ -165,7 +170,6 @@ class _HomeDashSpecialDayWidget extends StatelessWidget {
if (days.isNotEmpty) {
return Column(
spacing: 8,
children: days.map((ele) {
return Card(
child: ListTile(
@ -204,6 +208,9 @@ class _HomeDashSpecialDayWidget extends StatelessWidget {
separatorType: SeparatorType.symbol,
decoration: BoxDecoration(),
padding: EdgeInsets.zero,
onDone: () {
setState(() {});
},
),
const Gap(12),
Expanded(

View File

@ -106,9 +106,8 @@ class _AttachmentListState extends State<AttachmentList> {
}
if (widget.gridded) {
return Padding(
padding: widget.padding ?? EdgeInsets.zero,
child: Container(
return Container(
margin: widget.padding ?? EdgeInsets.zero,
decoration: BoxDecoration(
color: backgroundColor,
border: Border(
@ -151,22 +150,20 @@ class _AttachmentListState extends State<AttachmentList> {
.toList(),
),
),
),
);
}
return AspectRatio(
aspectRatio: (widget.data.firstOrNull?.data['ratio'] ?? 1).toDouble(),
child: Container(
return Container(
constraints: BoxConstraints(maxHeight: constraints.maxHeight),
child: ScrollConfiguration(
behavior: _AttachmentListScrollBehavior(),
child: ListView.separated(
padding: widget.padding,
shrinkWrap: true,
itemCount: widget.data.length,
itemBuilder: (context, idx) {
return Container(
constraints: constraints,
constraints: constraints.copyWith(maxWidth: widget.maxWidth),
child: AspectRatio(
aspectRatio: (widget.data[idx]?.data['ratio'] ?? 1).toDouble(),
child: GestureDetector(
@ -174,8 +171,7 @@ class _AttachmentListState extends State<AttachmentList> {
if (widget.data[idx]?.mediaType != SnMediaType.image) return;
context.pushTransparentRoute(
AttachmentZoomView(
data:
widget.data.where((ele) => ele != null && ele.mediaType == SnMediaType.image).cast(),
data: widget.data.where((ele) => ele != null && ele.mediaType == SnMediaType.image).cast(),
initialIndex: idx,
heroTags: heroTags,
),
@ -217,12 +213,10 @@ class _AttachmentListState extends State<AttachmentList> {
);
},
separatorBuilder: (context, index) => const Gap(8),
padding: widget.padding,
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
),
),
),
);
},
);

View File

@ -231,7 +231,7 @@ class _AttachmentZoomViewState extends State<AttachmentZoomView> {
children: [
IgnorePointer(
child: AccountImage(
content: account!.avatar,
content: account?.avatar,
radius: 19,
),
),
@ -246,7 +246,7 @@ class _AttachmentZoomViewState extends State<AttachmentZoomView> {
style: Theme.of(context).textTheme.bodySmall,
),
Text(
account.nick,
account?.nick ?? 'unknown'.tr(),
style: Theme.of(context).textTheme.bodyMedium,
),
],

View File

@ -24,6 +24,7 @@ class ChatMessage extends StatelessWidget {
final Function(SnChatMessage)? onReply;
final Function(SnChatMessage)? onEdit;
final Function(SnChatMessage)? onDelete;
final EdgeInsets padding;
const ChatMessage({
super.key,
@ -35,6 +36,7 @@ class ChatMessage extends StatelessWidget {
this.onReply,
this.onEdit,
this.onDelete,
this.padding = const EdgeInsets.only(left: 12, right: 12),
});
@override
@ -87,7 +89,9 @@ class ChatMessage extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
Padding(
padding: isCompact ? EdgeInsets.zero : padding,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!isMerged && !isCompact)
@ -98,6 +102,8 @@ class ChatMessage extends StatelessWidget {
const Gap(40),
const Gap(8),
Expanded(
child: Container(
constraints: BoxConstraints(maxWidth: 480),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -119,7 +125,7 @@ class ChatMessage extends StatelessWidget {
).fontSize(13),
],
),
if (isCompact) const Gap(4),
if (isCompact) const Gap(8),
if (data.preload?.quoteEvent != null)
StyledWidget(Container(
decoration: BoxDecoration(
@ -149,21 +155,23 @@ class ChatMessage extends StatelessWidget {
},
],
),
),
)
],
).opacity(isPending ? 0.5 : 1),
),
if (data.body['text'] != null && data.type == 'messages.new' && (data.body['text']?.isNotEmpty ?? false))
LinkPreviewWidget(text: data.body['text']!),
if (data.preload?.attachments?.isNotEmpty ?? false)
AttachmentList(
data: data.preload!.attachments!,
bordered: true,
// gridded: true,
maxHeight: 560,
maxWidth: 480,
minWidth: 480,
padding: const EdgeInsets.only(top: 8),
padding: padding.copyWith(top: 8),
),
if (!hasMerged && !isCompact) const Gap(12) else if (!isCompact) const Gap(6),
if (!hasMerged && !isCompact) const Gap(12) else if (!isCompact) const Gap(8),
],
),
),