kauemurakami / getx_pattern

Design pattern designed to standardize your projects with GetX on Flutter.
https://kauemurakami.github.io/getx_pattern
1k stars 235 forks source link

A working minimal example would be greatly appreciated #19

Closed ghost closed 3 years ago

ghost commented 3 years ago

Is there an example that showcases a project with this setup in action? I have been trying to change an existing project to this project recommendation.

  1. What is the difference between provider and services in the data folder?
  2. Where and how should be a dio object created in this setup? Along with the snippets from the VSCode, it would seem that everywhere the repository object is created an httpClient is to be used. Even on the bindings page. Doesn't it seem awkward?
  3. I have a singleton class that provides user information (username, profile pic, token, etc...) to pages. Which is initialized during login. Should this be changed to GetxService? Where should it be kept in this structure?
  4. Some services (like constantly checking for connectivity and doing some action based on the connectivity status) are a good candidate for GetXService. Where should it be placed?

I have been overwhelmingly fascinated by GetX and its uses. Thank you so much:heart:

ghost commented 3 years ago

Hi @kauemurakami please check a sample code that I have created after going through your ideas. Is this the kind of structure that you have planned?

https://github.com/paanoop/rnd_get_x

kauemurakami commented 3 years ago

1 - Providers x Services: The providers in the getx pattern is everything that provides you with data, be it a database, api, shared preferences, everything that is external to the application, in a way and you need to recover, and it demands some time and no logic for that, like a get in a url, or a select in a bank. Services in this context start with your question number 4, it is used as a controller "that does not die alone", it stays alive in your application while you finish, I, as well as you see a great advantage in the use with authentication , I also do this xD, token, user, so that we don’t need to make more gets in our api and retrieve that user, so GetXService, say auth_service, also provides you, but not data, information captured in your providers, in at some point, it is converted into information for your app, such as a list, model, an authenticated user, so it goes into the data folder, everything that is in date, is served to our application, such as models, apis, and services. And at this very moment I changed the approach to repositories.

2 - Your dio is a provider, just like http, but I recommend using GetConnect, a new thing for us to use apis hehe, I'll post an example at the end of this comment of mine, so your dio is a provider, your dio class must contain your called api, getUser, postUser, etc.

3 - Yes, change to a getxService, even to leave these observables in case you want to change, I don’t have an example "mine", that can show you using an auth service, but I leave everything to do with authentication there, like registration, login and logout, therefore whenever I need the user, or token, just give an AuthService a = Get.find () ... a.usuario.value.name, with this you can change your user and this will reflect in every application where this service with obs attribute is called.

4 - These static functions, I consider utilities, an example that you mentioned, I use the Package Connectivity, so I have the utils folder, where I leave this type of thing, when I will only check the internet connection, I will not do anything with it , if it was a service, then it's just for that, I create abstract classes with a function inside, what I call the idiot proof, since an abstract class cannot be instantiated, as well as my routes and pages in the pattern, this way you can create a function with return true or false and call without instantiating or searching the memory that way VerifyConnect.verify () ClassAbstract.function ().

About your example, it is basically that, but you have confused the concepts of services and providers a little, this is normal, there are several approaches about them, here is a repository that I just updated, at a glance, it is simple, it consumes api with getconnect, using state mixin a new super show feature from get, feel free to take any further questions, i will leave the issue open until tomorrow if i have any further comments.

https://github.com/kauemurakami/valorant-brasil

ghost commented 3 years ago

Thank you for such a detailed explaining and the example :smiley: I like the concepts that you've mentioned here. I will refine my little project so that it may be useful for other enthusiasts.

Regarding Get+Connect, I wanted to use it. But I couldn't find enough documents which helped me to accomplish

  1. Interceptor for injecting tokens
  2. Cancellation of an ongoing request
  3. Progress of a request/response
  4. Refresh token

I didn't look at the Get CLI. But very late after creating the sample. This is very much easier now https://www.youtube.com/watch?v=DteaBnjZLvk

ghost commented 3 years ago

The CLI package is very cool! But, when you create a project using your pattern in the Get CLI package, you are getting bindings, controllers, and view in separate folders under the module folder. This is somewhat different from your pattern. This is also somewhat ugly.

Screenshot from 2021-03-28 16-58-04

  1. Is there a reason for keeping binding in a binding folder rather than in the page folder?
  2. Is there an option to turn it off and go by strictly by your pattern as in the documents?
ghost commented 3 years ago

@kauemurakami it'd be a lot better and useful if the generator could generate like this. Screenshot from 2021-03-28 17-07-12 It is in fact very difficult to move the files and delete the folder every time. It is more easier to manually create a file and fill it in using the getcontroller or getbinding snippets.

Also, it'd be a lot better if the get create project creates the entire set of folders like the util, theme etc.

kauemurakami commented 3 years ago

hello my friend, well, I am not the maintainer of this package, this version is the packaged version of this readme structure, but I left it in disuse and I encourage everyone to create like this, I will see what I can do about it, but think about implementing, in the long run, because I already had some flaws, structures like the block in vscode, with click you generate a whole block, practically my module, without needing a cli, I'm leaving it aside a little because it already frustrated me quite haha, but for now, do it by hand, it’s not that big, with snippets helping you, and you’re sure to be up to date.

kauemurakami commented 3 years ago

I will close this issue for now, if you comment I will be here.