0

Hello there I am creating an application in Flutter and I am receiving JSON response from the API and I know that we need to parse the response to use in the Flutter app but I found that if we use the normal way as: jsonData['key'] to get and show the data because this way you can handle any kind of response easily but when I am using the models way then I am facing a lot of issues in which the data structure and data types included.

and I think the model only provides an object structure in which you can access data as an object way like jsonData.key instead of the jsonData['key'] this is only my thinking you can correct me if I am wrong here.

I just want to know that if I am using a non-model way then will it affect my app or not?

Shoaib Khan
  • 830
  • 1
  • 9
  • 17
  • idk but everyone hate getx because its not following the flutter's way – buncis Jan 23 '21 at 08:10
  • But I found GetX as a gem for the development because it provides a lot of functionality out of the box and especially managing routes, state management, local storage, and also some more utility like snackbar, dialog etc. These are the main reason why i use GetX. – Shoaib Khan Jan 23 '21 at 08:33
  • Also, this question is not only about the GetX because I know a lot of people are using and suggesting to use model way to parse JSON data for the app. – Shoaib Khan Jan 23 '21 at 08:35
  • @buncis Get was released on Apr 26, 2020 to pub.dev. 8 months later it's the 2nd most liked package in existence for Flutter/Dart (2875 likes). Only package with more likes (Provider at 3260) was released 27 months ago. You sure everyone hates Get? – Baker Jan 24 '21 at 00:45
  • @Baker I don't really fuss about this before, but I think its because old controversial stuffs like these. [#4981](https://github.com/flutter/website/pull/4981) [#4982](https://github.com/flutter/website/pull/4982) [#4983](https://github.com/flutter/website/pull/4983), it's not relevant to the questions though should be deleted. – buncis Jan 24 '21 at 02:12
  • @buncis there was some really questionable / off-putting claims about the package, I agree and I'm glad those were removed. I almost didn't try using Get due to the tone of the claims, but I'm glad I did. The package itself, is great. – Baker Jan 24 '21 at 03:39
  • Guys my question is not about the GetX package itself. I am just asking that is it acceptable to not use a Model to parse JSON data to dart object because it will work with using or not using I mean it will show data in UI if whether we are using the Model or not. so I just want to know will there be any issue if I am not using the model to parse JSON and using a direct response from the API to show/render in UI? – Shoaib Khan Jan 25 '21 at 05:29

3 Answers3

1

models are not resiliant. Your code will always break if the api is modified.

THEODORE
  • 917
  • 10
  • 12
0

Firstly, this has nothing to do with getX. Parsing json into models is much cleaner. You can compare two objects but how do you compare two jsons?

And if you need to create an instance of the object, how would you do so without a model? How would you pass it to another class or a function? I think the answers to this questions will solve your dilemma.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ali Akber
  • 492
  • 5
  • 9
0

Use an Object is a good practice because helps to take advantage of the strong typed language. This allows you to have a better debug process, catch potential error during writing time (and in compilation time). And this is independent of the state management package that you choose.

Frank Moreno
  • 304
  • 1
  • 7