I'm trying to refresh my page after upload image on server.
The problem is that after updating the profile image, the old image is displayed. After restarting the application, a new profile image is appearing.
Any help is appreciated. Thanks!
// upload image on server..............
upload() async {
var token = box.get('access_token');
var stream = new http.ByteStream(Stream.castFrom(imgPath!.openRead()));
var length = await imgPath!.length();
var uri = Uri.parse(editProfileUrl);
var request = new http.MultipartRequest("POST", uri);
Map<String, String> headers = {
"Authorization": "Bearer $token",
"Accept": "application/json"
};
request.headers.addAll(headers);
var multipartFile = new http.MultipartFile('profile_pic', stream, length,
filename: ("image_1.jpg"),
contentType: new MediaType('image', 'png')
);
request.files.add(multipartFile);
var response = await request.send();
print(response.statusCode);
if(response.statusCode == 200){
showDialog(
context: context,
builder: (BuildContext context) {
return Center(
child: AlertDialog(
content: new Text("Your proflie has been updated successfully."),
actions: <Widget>[
new ElevatedButton(
child: new Text("OK"),
onPressed: () {
setState(() {
// redirect on main page......
// here i want to refresh my page to see updated image
Navigator.push(
context, MaterialPageRoute(
builder: (context) => MyMatrimony()));
},
),
],
),
);
},
);