invalidates cachednetworkimage when new profile photo is uploaded

This commit is contained in:
Marty Fuhry
2023-02-12 16:00:36 -05:00
parent 432c2b9cda
commit 17c83be556
3 changed files with 21 additions and 21 deletions
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:image_picker/image_picker.dart';
@@ -72,7 +73,7 @@ class UploadProfileImageState {
class UploadProfileImageNotifier
extends StateNotifier<UploadProfileImageState> {
UploadProfileImageNotifier(this._userSErvice)
UploadProfileImageNotifier(this._userService)
: super(
UploadProfileImageState(
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);
var res = await _userSErvice.uploadProfileImage(file);
var res = await _userService.uploadProfileImage(file);
if (invalidateUrl != null) {
await CachedNetworkImage.evictFromCache(invalidateUrl);
}
if (res != null) {
debugPrint("Succesfully upload profile image");