Post link expand

 Cache link expansion image
This commit is contained in:
LittleSheep 2024-08-19 19:56:44 +08:00
parent cf1cfecb08
commit e45d9b39d5
3 changed files with 29 additions and 11 deletions

View File

@ -1,6 +1,8 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:get/get.dart';
import 'package:solian/platform.dart';
import 'package:solian/providers/link_expander.dart';
import 'package:url_launcher/url_launcher_string.dart';
@ -9,6 +11,12 @@ class LinkExpansion extends StatelessWidget {
const LinkExpansion({super.key, required this.content});
Widget _buildImage(String url, {double? width, double? height}) {
return PlatformInfo.canCacheImage
? CachedNetworkImage(imageUrl: url, width: width, height: height)
: Image.network(url, width: width, height: height);
}
@override
Widget build(BuildContext context) {
final linkRegex = RegExp(
@ -43,20 +51,17 @@ class LinkExpansion extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if ([
snapshot.data!.icon != null &&
(snapshot.data!.icon?.startsWith('http') ?? false),
(snapshot.data!.icon?.isNotEmpty ?? false),
snapshot.data!.siteName != null
].any((x) => x))
Row(
children: [
if (snapshot.data!.icon != null &&
(snapshot.data!.icon?.startsWith('http') ??
false))
if (snapshot.data!.icon?.isNotEmpty ?? false)
ClipRRect(
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
child: Image.network(
child: _buildImage(
snapshot.data!.icon!,
width: 32,
height: 32,
@ -68,14 +73,17 @@ class LinkExpansion extends StatelessWidget {
style: Theme.of(context).textTheme.labelLarge,
),
],
).paddingOnly(bottom: 8),
).paddingOnly(
bottom:
(snapshot.data!.icon?.isNotEmpty ?? false) ? 8 : 4,
),
if (snapshot.data!.image != null &&
(snapshot.data!.image?.startsWith('http') ?? false))
ClipRRect(
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
child: Image.network(
child: _buildImage(
snapshot.data!.image!,
),
).paddingOnly(bottom: 8),

View File

@ -33,10 +33,12 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
final resp = await provider.getCurrentStatus();
final status = AccountStatus.fromJson(resp.body);
if (mounted) {
setState(() {
_accountStatus = status;
});
}
}
void _closeDrawer() {
rootScaffoldKey.currentState!.closeDrawer();

View File

@ -10,6 +10,7 @@ import 'package:solian/shells/title_shell.dart';
import 'package:solian/widgets/account/account_avatar.dart';
import 'package:solian/widgets/account/account_profile_popup.dart';
import 'package:solian/widgets/attachments/attachment_list.dart';
import 'package:solian/widgets/link_expansion.dart';
import 'package:solian/widgets/markdown_text_content.dart';
import 'package:solian/widgets/posts/post_tags.dart';
import 'package:solian/widgets/posts/post_quick_action.dart';
@ -349,6 +350,11 @@ class _PostItemState extends State<PostItem> {
),
],
),
LinkExpansion(content: item.body['content']).paddingOnly(
left: 8,
right: 8,
top: 4,
),
_buildFooter().paddingOnly(left: 16),
if (attachments.isNotEmpty)
Row(
@ -445,6 +451,8 @@ class _PostItemState extends State<PostItem> {
if (widget.item.repostTo != null && widget.isShowEmbed)
_buildRepost(context).paddingOnly(top: 4),
_buildFooter().paddingOnly(left: 12),
LinkExpansion(content: item.body['content'])
.paddingOnly(top: 4),
],
),
),