how to make state_provider rebuild when i select image using image_picker then i select another one and update on state_provider but UI not updating. #3429
Unanswered
pakkawat-boonsri
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
im doing app that can selete image then upload to ftp server by using ip. and download after that and then update to state_provider.
`final imageFromGallery = await ImagePicker().pickImage(source: source);
if (imageFromGallery != null) {
final profileImage = await ref
.read(profileControllerNotifierProvider.notifier)
.uploadProfileImage(imageFromGallery);
}
Future<File?> uploadProfileImage(
XFile imageFile,
) async {
final user = _ref.read(userProvider)?.first;
File tmpFile = File(imageFile.path);
final appDocpath = await getTemporaryDirectory();
state = true;
final File newTempFile =
await tmpFile.copy("${appDocpath.path}/${user!.id}_profileImage.jpg");
final profileImage = await _profileRepository.uploadImageToServer(
localImageFile: newTempFile,
fileName: "${user.id}_profileImage.jpg",
);
state = false;
return profileImage;
}
Future<File?> uploadImageToServer({
required File localImageFile,
required String fileName,
// required bool isUploadImage,
}) async {
final ftpServer = FTPConnect(
FtpClient.host,
user: FtpClient.username,
pass: FtpClient.password,
showLog: true,
);
await ftpServer.connect();
await ftpServer.createFolderIfNotExist("ProfileImage");
await ftpServer.changeDirectory("ProfileImage");
await ftpServer.setTransferType(TransferType.binary);
await ftpServer.uploadFile(localImageFile, sRemoteName: fileName);
await ftpServer.setTransferType(TransferType.auto);
}
Future<File?> getProfileImageIfExist({
required File localImageFile,
required String fileName,
}) async {
final ftpServer = FTPConnect(
FtpClient.host,
user: FtpClient.username,
pass: FtpClient.password,
showLog: true,
);
}
`
then what happen is when i upload and download a new image and update to state_provider but then UI is not updating
what i think what happen is state_provider not rebuilding because data inside is same as before but the image that i selected is not the same.
Beta Was this translation helpful? Give feedback.
All reactions