2

I'm trying to implement Clean Architecture in my flutter app. There is a module named Purchase Order in my app. This contains List Screen, Filter Screen, Add Purchase Order Screen.

Currently, I have one controller (GetxController) for all of them. All of the business logic for all of those screens is included in that controller. The reason for not having separate controllers is the dependency on these screens on each other.

Let's say the user applies filters from Filter Screen, which should update the List Screen. Likewise, the user can remove filters and change some filter values from the List Screen.

Likewise, if the user adds a new Purchase Order, that should update the List Screen with the newly added Purchase Order

How to achieve the communication between multiple controllers in accordance with the clean architecture.

Manoranjan
  • 985
  • 10
  • 14
ASAD HAMEED
  • 2,296
  • 1
  • 20
  • 36
  • For starters, can you share what you call Clean Architecture? Are you referring to Uncle Bob's one: https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html ? – Plumillon Forge Feb 20 '23 at 18:25
  • Yes, I'm referring to this one. – ASAD HAMEED Feb 22 '23 at 04:31
  • this seems to be a state management problem, You have many options for synchronizing changes between all of them, using value notifier, Rx observables which Getx offers, but Ide recommend implementing a raw custom broadcast stream that can be listenable on all of them, however, we can't have a good overview about your case by only text, you should include your code so we can help. – Gwhyyy Feb 22 '23 at 22:29
  • I would go with BLoC package in your case: https://bloclibrary.dev/#/. Check the Todos app example in their doc. – Arton Hoxha Feb 27 '23 at 08:34

3 Answers3

1

Hope you are fine I believe the issue here is a state management issue, not a clean architecture issue.

I would approach it in 2 different ways:

1-Same controller with copyWith state: you can have one controller and 3 listeners on each screen the state should hold the 3 screens state -> also it should implement copyWith function copyWith creates a new instance of the state with previous data in case you want to modify a parameter and keep the other ones therefore whenever you want to update a screen, all screens will be updated.

2- Controllers and listners the second one is having a separate controller for each screen, and a listener on the constructor of each one, whenever a controller has changes the others will be notified.

Rami Al Debs
  • 111
  • 5
1

There is a great guy answered this question. https://stackoverflow.com/a/67224552/10766511

You can use Get.find<FirstController>().valueFromFirstController to access different controller values

So, in clean architecture you will be able to store it in different packages and fiels. I would suggest you to use dependency injection also, to achieve this, you can use get_it package

Nikita Shadkov
  • 372
  • 3
  • 11
1

I use get_cli to manage and organize my projects And I suggest this to you because it is a very regular structure and good management for projects

get_cli give you the best structure for view, controller, model, and providers

Installation:

  1. flutter pub global activate get_cli
  2. in your [project folder]: get init
Faiz Ahmad Dae
  • 5,653
  • 2
  • 14
  • 19