Flutter/Dart: Communication between features in Clean Architecure - flutter

I'm new to flutter/dart and I'm trying to create a little application using a Clean Architecture design.
I read some blogs and several presentations of Uncle Bob's Clean Architecture before starting to code to get the most of it and now it's time to implement it.
I guess my application could be divided in 3 main features :
authentication
classes (get access to lessons/quizzes on specific subjects)
admin (manage user, create lessons etc..)
I started to implement the authentication feature following the clean pattern, that's to say with a domain, data and presentation layer and I guess I did it quite well. It's (almost) fully tested (I'm trying to do some TDD) and seems to work as I wanted.
Now comes the problem. I want to implement the classes feature. I wish it could be independent of the authentication but it's not the case... The classes feature need to get the authenticated user from the authentication feature. I searched a lot on the internet but I can't find how to implement Clean Architecture with multiple features that need to share some data.
So there are my 2 questions:
How to pass data from a feature to another ?
How to inject dependency in a feature that need data from another feature ? (I used get_it for the authentication feature and inject all dependencies in the main() method before building the app. Since it did not need any external data it worked well. Now it's seem not possible to do the same for the classes feature since it first needs to get some data from the authentication feature).
Thanks in advance for your answers.

Along with your 3 features you should add another called core and inside that folder you can add stuffs that need to be shared. It worked for me . Good luck

One option is if you instantiate classes after the user has already logged in, you can pass that data in as a constructor parameter.
More generally, Provider is probably the best dependency injection tool for flutter. If you "provide" the authentication class to the widget tree for the rest of the app, you can say at any point below it, Provider.of(context) to access it and any public field it has.

Hope you're still working on Flutter projects after that long time.
I've been fiddling around with Uncle Bob's Clean architecture, and I managed to implement it in Flutter few months ago.
It's perfect, it separates your code into components (modules if you're coming from a native Android development environment) and isolates your data sources, so if you want to change the way you make API requests for example, you'll only need to change the remote data source part in your app, and all your application should work as expected.
I have made a test app using Clean Architecture I just uploaded on github and added a humble readme that describes the basic architecture and components of the app, I'll work on written articles describing the code very soon.
For now you can access the repo from here

I'm trying to find an answer to this for some time now... My solution was to create some transformation methods in the model class. For example, I have an ProductModel in the home feature file (from where i can add products to the cart), and an ProductInOrderHistoryModel in the order history feature file. So in the ProductInOrderHistoryModel file I have a method called toProductModel that gets an instance of ProductInOrderHistoryModel and transform to a ProductModel. That way I can add a product to the cart directly from my history order page.
Probably it's not the best solution, and the Uncle Bom would be really mad at me. But it was how I manage to solve my problem...

Related

Setting up REST-API on top of GraphQL-API (using apollo gateway?)

I am working on a GRANDstack (GraphQL-React-Apollo-Neo4jDatabase) project and got told that it now needs an additional REST-API without making huge changes to the existing backend and GraphQL-API. And of course we have to be quick about it.
We found this (Apollo Gateway): https://medium.com/tkssharma/an-api-gateway-is-a-microservice-pattern-where-a-separate-service-is-built-to-sit-in-front-of-your-be4b16861d40
We plan on using this to set that new REST-API on top because we know we will need microservices soon enough as well. So I guess, this can be set up in some form with the already included Apollo. But I have yet to fully understand it.
Does anyone have some experience with this? Or does anyone know a project that implements this and can be checked out? I'd like more material about this that contains actual code. Especially about setting up such a gateway to put a REST-API on top.
If there is something easier and better documented than this Apollo gateway, please let me know! Open to ideas, but not complete overkills (Though we are not allowed to just put REST directly into our backend, it has to stay quite untouched).
Thank you very much!
In short: Our current backend offers GraphQL-API which works just fine. But one of our customers (in this picture "client") needs a REST-API. So we hope on using a gateway (?) which should be placed before/upon our backend in a separate docker container probably, takes in HTTP-requests from the user and then asks our backend in graphQL for the needed data.
If anyone ever stumbles upon this, we decided to do the following:
Since we have to be quick about it, we will set up another docker container, that contains a small server, which accepts data via a REST-API. Depending on the received data, it calls specific GraphQL-Queries/Mutations on our backend. Easy. No additional 3rd-party software. Simple just wins.
Have a good one!

Ionic Framework different databases

I am new to Ionic, currently learning to develop using Ionic. I just have a question, I don't know if it is possible.
My plan is to create an Ionic app, one application/code base only, for browser as admin, and mobile app for the user. I will limit their access based on the user.
Is it possible that I have two different database on my app?
On my browser I will use REST API to connect to MySQL.
On the generated mobile app, I will use an offline database.
Hope you can enlighten me. The goal is to develop a one application for web and mobile app. But I don't know if it is possible.
Thank you.
Your question is not very clear, I will try to answer according to what I understood.
You didn't mention the back-end, so I am assuming you are using the same data structure for both, e.g(user has id and name and phone, in both, identically)
In this case you can create a setting file where you will save your constant connection strings along with any necessary information(create a any-name.ts file in your root folder and just write down
export let example = {...}
and whenever you need, just import your any-name.ts and use the object inside.
If the data structure is also different, I thinks you will be doing massive works to maintain such an app, but the idea would be creating 2 of each functionalities having the same output but different inputs.
P.S in both cases I mentioned you will need to detect the platform to define which function/information is adequate.

Azure Communication Services Web Calling in MVC

All of the examples for ACS are using Nodejs and VS Code... and thats fine if you're building a new app, and if you have some kind of background with React. I do not... and I'm willing to bet most web devs maintaining and builing MVC apps don't.
I'm not so daft that I can't get a Nodejs app working, I can get the web calling hero sample to run without any issues...
However, I think for MVC we probably should be looking at this solution
https://github.com/Azure/communication-ui-library/tree/main/samples/StaticHtmlComposites
and I can't get it going... Not only that... but even if I did get it running how would one implement into an existing MVC app...
Has anyone successfully implemented ACS web calling/video into an existing MVC app, and how did you do it? ...the internet is currently a barren wasteland when it comes to this topic.
ANSWER as of 7/7/2021
Step 1: Follow all of the steps from here
https://github.com/Azure/communication-ui-library/tree/main/samples/StaticHtmlComposites
Step 2: Take the newly created/bundled callComposite.js file and add it to your existing or new MVC web project. I added mine to wwwroot/js...
Step 3: Create a view (however you choose to do that...) and copy the html and javascript from the index page in the project I linked to above. (if you don't care about chat you can remove all the related js). You'll need to replace the callComposite.js script link with the newly added one.
Step 4: You need a controller that will generate the token and userId.
I created a web api controller so that a new token and userId was generated essentially when the page was loaded. NOTE: make sure you're using async javascript OR just put the callAdapter code block in a timeout (mine is 2 seconds with a loading screen) Secondary Note: I got all of the code from the Web Calling Hero Sample out of the calling/controllers/UserTokenController.cs
Final step: say a small prayer, cross your fingers, grab a rabbits foot and rub it. then run it and it could/might/probably/possibly work the first time... but probably not. you'll need to adjust for your own set up.
For you future people. Please post an updated solution. This is literally the only resource for Azure Communication Services Web Calling on MVC on the internet (as of the time of this posting). Be a hero, tell us a better, easier way.

Flutter Future Provider and Sqflite (the right usage)

As a beginner I need an architectural advice for following scenario.
My application writes a tiny amount of data and return a tiny query result to the user interface (from sqflite) for each user interaction (click).
There can be at least three ways to do so;
Future Provider (Most appropriate way as I see)
ChangeNotifierProvider & Future Builder
Using Flutter List and do all db operations in the background with using future-then functions.
I couldn't succeed on Future Provider and couldn't find a similar example. (almost all future provider examples are related with web services not sqflite)
Because of this I started asking which way is right or can be another way? Future Provider can be the most appropriate way if you say, I will focus on this.
Thank you very much in advance.
Best regards.
If you want to return query based on the user input, you need to go with the second option, i have personally developed a production level app using this strategy and it works like charm.
Here's the link to my github repository for that app, if you feel any difficulty in implementation you may ask.
Code that contains `ChangeNotifierProvider' for DateTime
https://github.com/asadamatic/Daily-Todo/blob/master/lib/main.dart
Code that contains Consumer for ChangeNotifierProvider for DateTime
https://github.com/asadamatic/Daily-Todo/blob/master/lib/Screens/HomeScreen.dart
You nay want to check out the app and see if you can relate to it,
https://play.google.com/store/apps/details?id=com.legacyllc.dailytodo

Dynamically Change API Environments Google Rollout Track

I'm developing an Ionic(3 / 4)(Angular 4 - 7)-Cordova / Capacitor Cross Platform Application(s). I'm interested in switching API env based on the current rollout track in the Google Play Store. For example, once an application has been successfully tested and recommended to continue staging/production. I would like to have the API env dynamically changed (e.g., using a different URI domain to connect to REST API ) dependent on the Google Play Store Track.
I'm aware that I can use Google Developer Play Store API to identify / list versions and available tracks yet, I'm unaware if there's already an implementation or solution. I'm perfectly willing to design a solution though, I figure I find out if it's been done already rather than reinvent the wheel.
I'm hoping to implement a solution either to the REST API BACKEND or in the ionic framework layer rather than an integration at the native layer for scalability per-project. The purpose of doing this would enable CI rather than rebuilding the project and change the API URI domain for every environment. Any assistance in this matter would be greatly appreciated.
So, if anyone's interested. The approach highlighted above is possible, couldn't get an answer so I just created something. Using Google Play Developer API. The process flow is as follows:
[]
For now it's a working prototype perhaps its not very efficient; I suppose it can be improved if the request was issued from a single server, or microservice. Though, I wanted to make the code recyclable and it's isolated from both the mobile application & Node Server.
If you are interested in learning more or would like to work on project. Please feel free to contact me.