Skip to content

Commit

Permalink
fix: 修复多次请求图片的问题 (#399)
Browse files Browse the repository at this point in the history
手动设置 cache key,避免因为 s3 api 导致的问题
  • Loading branch information
he0119 authored Feb 7, 2024
1 parent bad577a commit b9f560f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/

- 修复搜索位置无法显示的问题
- 捕获解码异常并修复在网页无法打开物品管理主页的问题
- 修复多次请求图片的问题

## [0.9.7] - 2024-02-05

Expand Down
2 changes: 2 additions & 0 deletions lib/storage/view/picture_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions lib/utils/parse_url.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// 从 url 中获取缓存 key
String getCacheKey(String url) {
final uri = Uri.parse(url);
return '${uri.host}:${uri.port}${uri.path}';
}
2 changes: 2 additions & 0 deletions lib/widgets/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b9f560f

Please sign in to comment.