Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复多次请求图片的问题 #399

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading