0

I have a webserver, that always returns a String in this json format:

{"status":100,"content":[{"version":"2.2.2"}]}

I want my flutter app to map this json to a Map<String, dynamic>` everytime on appstart to check if a new version is available.

To reduce server load, I don't want to use a websocket for this.

Since I am completely unexperienced with darts web i/o, I would appreciate some advice on where to start with this. I am lacking imagination and knowledge on what is needed for this usecase.

Salatgurke
  • 1,554
  • 1
  • 13
  • 35

1 Answers1

0

You can add a splash screen for checking if you are using the latest version or not. You can use the get_version package to check the current version of the app. Now on your splash screen, You can call your API and get the JSON. now you can convert your JSON into a readable class using Models. You can use any famous JSON to Dart converter(I use this one https://javiercbk.github.io/json_to_dart/). Now once you get both your current version and latest version then you can update your app status accordingly. Alternatively, you can achieve the same functionality using Firebase remote configs.

You can read this article by the flutter team on how to fetch data from the internet. https://flutter.dev/docs/cookbook/networking/fetch-data

Zeeshan Hussain
  • 802
  • 6
  • 9
  • I am struggling at the "how to call your api" in dart without a websocket rather than the splashscreen – Salatgurke Jul 29 '20 at 18:31
  • @Salatgurke you can read this article https://flutter.dev/docs/cookbook/networking/fetch-data – Zeeshan Hussain Jul 29 '20 at 18:33
  • For the URL I am using I get an exception: SocketException: Failed host lookup: 'connect.horizonpedia.com' (OS Error: No address associated with hostname, errno = 7) – Salatgurke Jul 31 '20 at 01:16