mirror of
https://github.com/immich-app/immich.git
synced 2025-01-06 11:56:46 +01:00
invalidates cachednetworkimage when new profile photo is uploaded
This commit is contained in:
parent
432c2b9cda
commit
17c83be556
3 changed files with 21 additions and 21 deletions
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
@ -72,7 +73,7 @@ class UploadProfileImageState {
|
||||||
|
|
||||||
class UploadProfileImageNotifier
|
class UploadProfileImageNotifier
|
||||||
extends StateNotifier<UploadProfileImageState> {
|
extends StateNotifier<UploadProfileImageState> {
|
||||||
UploadProfileImageNotifier(this._userSErvice)
|
UploadProfileImageNotifier(this._userService)
|
||||||
: super(
|
: super(
|
||||||
UploadProfileImageState(
|
UploadProfileImageState(
|
||||||
profileImagePath: '',
|
profileImagePath: '',
|
||||||
|
@ -80,12 +81,17 @@ class UploadProfileImageNotifier
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final UserService _userSErvice;
|
final UserService _userService;
|
||||||
|
|
||||||
Future<bool> upload(XFile file) async {
|
Future<bool> upload(XFile file, {
|
||||||
|
String? invalidateUrl,
|
||||||
|
}) async {
|
||||||
state = state.copyWith(status: UploadProfileStatus.loading);
|
state = state.copyWith(status: UploadProfileStatus.loading);
|
||||||
|
|
||||||
var res = await _userSErvice.uploadProfileImage(file);
|
var res = await _userService.uploadProfileImage(file);
|
||||||
|
if (invalidateUrl != null) {
|
||||||
|
await CachedNetworkImage.evictFromCache(invalidateUrl);
|
||||||
|
}
|
||||||
|
|
||||||
if (res != null) {
|
if (res != null) {
|
||||||
debugPrint("Succesfully upload profile image");
|
debugPrint("Succesfully upload profile image");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
@ -47,7 +48,6 @@ class HomePageAppBar extends ConsumerWidget with PreferredSizeWidget {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
String endpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
String endpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||||
var dummy = Random().nextInt(1024);
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Scaffold.of(context).openDrawer();
|
Scaffold.of(context).openDrawer();
|
||||||
|
@ -57,8 +57,8 @@ class HomePageAppBar extends ConsumerWidget with PreferredSizeWidget {
|
||||||
radius: 18,
|
radius: 18,
|
||||||
child: CircleAvatar(
|
child: CircleAvatar(
|
||||||
backgroundColor: Theme.of(context).primaryColor.withOpacity(0.1),
|
backgroundColor: Theme.of(context).primaryColor.withOpacity(0.1),
|
||||||
backgroundImage: NetworkImage(
|
backgroundImage: CachedNetworkImageProvider(
|
||||||
'$endpoint/user/profile-image/${authState.userId}?d=${dummy++}',
|
'$endpoint/user/profile-image/${authState.userId}',
|
||||||
),
|
),
|
||||||
radius: 17,
|
radius: 17,
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
|
@ -22,7 +23,6 @@ class ProfileDrawerHeader extends HookConsumerWidget {
|
||||||
AuthenticationState authState = ref.watch(authenticationProvider);
|
AuthenticationState authState = ref.watch(authenticationProvider);
|
||||||
final uploadProfileImageStatus =
|
final uploadProfileImageStatus =
|
||||||
ref.watch(uploadProfileImageProvider).status;
|
ref.watch(uploadProfileImageProvider).status;
|
||||||
var dummy = Random().nextInt(1024);
|
|
||||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
|
||||||
buildUserProfileImage() {
|
buildUserProfileImage() {
|
||||||
|
@ -34,15 +34,16 @@ class ProfileDrawerHeader extends HookConsumerWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uploadProfileImageStatus == UploadProfileStatus.idle) {
|
if (uploadProfileImageStatus == UploadProfileStatus.idle ||
|
||||||
|
uploadProfileImageStatus == UploadProfileStatus.success) {
|
||||||
if (authState.profileImagePath.isNotEmpty) {
|
if (authState.profileImagePath.isNotEmpty) {
|
||||||
return CircleAvatar(
|
return CircleAvatar(
|
||||||
backgroundColor: Theme.of(context).primaryColor,
|
backgroundColor: Theme.of(context).primaryColor,
|
||||||
radius: 35,
|
radius: 35,
|
||||||
child: CircleAvatar(
|
child: CircleAvatar(
|
||||||
radius: 34,
|
radius: 34,
|
||||||
backgroundImage: NetworkImage(
|
backgroundImage: CachedNetworkImageProvider(
|
||||||
'$endpoint/user/profile-image/${authState.userId}?d=${dummy++}',
|
'$endpoint/user/profile-image/${authState.userId}',
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
),
|
),
|
||||||
|
@ -56,16 +57,6 @@ class ProfileDrawerHeader extends HookConsumerWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uploadProfileImageStatus == UploadProfileStatus.success) {
|
|
||||||
return CircleAvatar(
|
|
||||||
radius: 35,
|
|
||||||
backgroundImage: NetworkImage(
|
|
||||||
'$endpoint/user/profile-image/${authState.userId}?d=${dummy++}',
|
|
||||||
),
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uploadProfileImageStatus == UploadProfileStatus.failure) {
|
if (uploadProfileImageStatus == UploadProfileStatus.failure) {
|
||||||
return const CircleAvatar(
|
return const CircleAvatar(
|
||||||
radius: 35,
|
radius: 35,
|
||||||
|
@ -89,6 +80,9 @@ class ProfileDrawerHeader extends HookConsumerWidget {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
|
final url = '$endpoint/user/profile-image/${authState.userId}';
|
||||||
|
await CachedNetworkImage.evictFromCache(url);
|
||||||
|
print('done evicting image');
|
||||||
var success =
|
var success =
|
||||||
await ref.watch(uploadProfileImageProvider.notifier).upload(image);
|
await ref.watch(uploadProfileImageProvider.notifier).upload(image);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue