invalidates cachednetworkimage when new profile photo is uploaded
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@@ -47,7 +48,6 @@ class HomePageAppBar extends ConsumerWidget with PreferredSizeWidget {
|
||||
);
|
||||
} else {
|
||||
String endpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
var dummy = Random().nextInt(1024);
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Scaffold.of(context).openDrawer();
|
||||
@@ -57,8 +57,8 @@ class HomePageAppBar extends ConsumerWidget with PreferredSizeWidget {
|
||||
radius: 18,
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Theme.of(context).primaryColor.withOpacity(0.1),
|
||||
backgroundImage: NetworkImage(
|
||||
'$endpoint/user/profile-image/${authState.userId}?d=${dummy++}',
|
||||
backgroundImage: CachedNetworkImageProvider(
|
||||
'$endpoint/user/profile-image/${authState.userId}',
|
||||
),
|
||||
radius: 17,
|
||||
),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
@@ -22,7 +23,6 @@ class ProfileDrawerHeader extends HookConsumerWidget {
|
||||
AuthenticationState authState = ref.watch(authenticationProvider);
|
||||
final uploadProfileImageStatus =
|
||||
ref.watch(uploadProfileImageProvider).status;
|
||||
var dummy = Random().nextInt(1024);
|
||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
buildUserProfileImage() {
|
||||
@@ -34,15 +34,16 @@ class ProfileDrawerHeader extends HookConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
if (uploadProfileImageStatus == UploadProfileStatus.idle) {
|
||||
if (uploadProfileImageStatus == UploadProfileStatus.idle ||
|
||||
uploadProfileImageStatus == UploadProfileStatus.success) {
|
||||
if (authState.profileImagePath.isNotEmpty) {
|
||||
return CircleAvatar(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
radius: 35,
|
||||
child: CircleAvatar(
|
||||
radius: 34,
|
||||
backgroundImage: NetworkImage(
|
||||
'$endpoint/user/profile-image/${authState.userId}?d=${dummy++}',
|
||||
backgroundImage: CachedNetworkImageProvider(
|
||||
'$endpoint/user/profile-image/${authState.userId}',
|
||||
),
|
||||
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) {
|
||||
return const CircleAvatar(
|
||||
radius: 35,
|
||||
@@ -89,6 +80,9 @@ class ProfileDrawerHeader extends HookConsumerWidget {
|
||||
);
|
||||
|
||||
if (image != null) {
|
||||
final url = '$endpoint/user/profile-image/${authState.userId}';
|
||||
await CachedNetworkImage.evictFromCache(url);
|
||||
print('done evicting image');
|
||||
var success =
|
||||
await ref.watch(uploadProfileImageProvider.notifier).upload(image);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user