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

View File

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

View File

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

View File

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

View File

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