From 4cc97da1fd024999672fdebaa70f3832f275366d Mon Sep 17 00:00:00 2001 From: uy_sun Date: Wed, 7 Feb 2024 10:55:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=9B=BE=E7=89=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 手动设置 cache key,避免因为 s3 api 导致的问题 --- CHANGELOG.md | 1 + lib/storage/view/picture_page.dart | 2 ++ lib/utils/parse_url.dart | 5 +++++ lib/widgets/avatar.dart | 2 ++ 4 files changed, 10 insertions(+) create mode 100644 lib/utils/parse_url.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a363eb6..2153b2b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/ - 修复搜索位置无法显示的问题 - 捕获解码异常并修复在网页无法打开物品管理主页的问题 +- 修复多次请求图片的问题 ## [0.9.7] - 2024-02-05 diff --git a/lib/storage/view/picture_page.dart b/lib/storage/view/picture_page.dart index 7411e4b3..aad93e12 100644 --- a/lib/storage/view/picture_page.dart +++ b/lib/storage/view/picture_page.dart @@ -7,6 +7,7 @@ import 'package:smarthome/storage/bloc/blocs.dart'; import 'package:smarthome/storage/model/models.dart'; import 'package:smarthome/storage/repository/storage_repository.dart'; import 'package:smarthome/utils/launch_url.dart'; +import 'package:smarthome/utils/parse_url.dart'; import 'package:smarthome/utils/show_snack_bar.dart'; import 'package:smarthome/widgets/center_loading_indicator.dart'; import 'package:smarthome/widgets/error_message_button.dart'; @@ -102,6 +103,7 @@ class PictureScreen extends StatelessWidget { loadingBuilder: (context, event) => const CenterLoadingIndicator(), imageProvider: CachedNetworkImageProvider( state.picture.url!, + cacheKey: getCacheKey(state.picture.url!), ), minScale: PhotoViewComputedScale.contained, maxScale: PhotoViewComputedScale.covered * 5, diff --git a/lib/utils/parse_url.dart b/lib/utils/parse_url.dart new file mode 100644 index 00000000..2a3460b1 --- /dev/null +++ b/lib/utils/parse_url.dart @@ -0,0 +1,5 @@ +/// 从 url 中获取缓存 key +String getCacheKey(String url) { + final uri = Uri.parse(url); + return '${uri.host}:${uri.port}${uri.path}'; +} diff --git a/lib/widgets/avatar.dart b/lib/widgets/avatar.dart index ed0ade8d..addfa9f7 100644 --- a/lib/widgets/avatar.dart +++ b/lib/widgets/avatar.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:smarthome/utils/parse_url.dart'; class MyCircleAvatar extends StatelessWidget { final String? avatarUrl; @@ -30,6 +31,7 @@ class MyCircleAvatar extends StatelessWidget { ), placeholder: (context, url) => const CircularProgressIndicator(), errorWidget: (context, url, error) => const Icon(Icons.error), + cacheKey: getCacheKey(url), ); } else { return CircleAvatar(