'Where to place the calculative logic for Flutter BLOC apps
I am trying to build a flutter app in BLoC, which I am new to. I need to get data from API ( like sunrise/sunset) and perform calculations on the sunrise/sunset data like calculating the day duration and some other things.
Where should I place the calculation logic? inside State part or just before the UI logic or should I perform these as soon as I get the data from the server?
Any good pointers on where this logic should be placed?
I have placed in UI logic but really want to understand the best practices from flutter community?
Solution 1:[1]
Like all programming and projects, Flutter does not lag behind in its structure. There are many ways to organize your project logic (UI, Models, API, etc...) I use one called TDD; I like this way because it is exactly what you need, to separate between all the Flutter UI, its Domain (which is the logic) and finally the Data (calls to the server). I leave the following links and pictures for you to take a look at them.
https://resocoder.com/flutter-clean-architecture-tdd/
More than anything is the explanation and its Youtube videos, you will like it, otherwise you can just take as the file structure and guide you that way.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Daniel Roldán |