Updated data not showing on Flutter Web App

Viewed 113

In my flutter app, I have two pages to show and add/edit some data. I'm using provider and consumer structer but when I add or edit a data and navigate back to page which I show my data, they are not being updated.

Provider function is running to get data but I guess php side has some problems. When get request arrives to php file first it checks for the keys.

if (array_key_exists("parentid", $_GET)&&array_key_exists("moduleid", $_GET)) 

Then I separate request methods like this:

if($_SERVER['REQUEST_METHOD'] === 'GET') {..}
if($_SERVER['REQUEST_METHOD'] === 'DELETE') {..}

Here is a full codes:

if (array_key_exists("parentid", $_GET)&&array_key_exists("moduleid", $_GET)) {

error_log("This condition work fine");
$parentid = $_GET['parentid'];
$moduleid = $_GET['moduleid'];


if($parentid == '' || !is_numeric($parentid)) {
$response = new Response();
$response->setHttpStatusCode(400);
$response->setSuccess(false);
$response->addMessage("Parent ID cannot be blanck or must be numeric");
$response->send();
exit;
}
if($moduleid == '' || !is_numeric($moduleid)) {
$response = new Response();
$response->setHttpStatusCode(400);
$response->setSuccess(false);
$response->addMessage("Module ID cannot be blanck or must be numeric");
$response->send();
exit;
}


if($_GET) {
    error_log("here we stack");
    try { 
       
       $querySetNames = $readDB->prepare("SET NAMES 'utf8'");
       $querySetNames->execute();
       

        $query = $readDB->prepare('SELECT ... }

if($_SERVER['REQUEST_METHOD'] === 'DELETE') {..}
if($_SERVER['REQUEST_METHOD'] === 'PATCH') {..}

}

I tried to use if($_SERVER['REQUEST_METHOD'] == 'GET') {..} and if($_SERVER['REQUEST_METHOD'] === 'GET') {..} instead of if($_GET). But it didn't work.

Because of that I could't get updated data. What could be the reason?

1 Answers

Here is the solution, I couldn't find the real answer which I found on this website but If you having the same problem you need to add random numbers end of the API URL. for example if your API URL is:

final response = await http
  .get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));

it must be:

import 'dart:math';
Random random = new Random();
int randomNumber = random.nextInt(100);

final response = await http
      .get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1?srn='+randomNumber ));
Related