Flutter + Provider + Sqflite: Aggregated data state management - flutter

Background
Say I have 30 sqlite db entities with their corresponding individual dart class models. Of those, many are aggregated and shown in several widgets of the app. CRUD operations should re-run the corresponding aggregation and update the respective ui/widgets that consume the data.
Current state
Today I read from the db every time I build the widgets.
Need
How can I have generic provider/listener for the aggregations as well as the entities without creating one provider for each entity and aggregated view? It should be able to resolve which widgets to update.
I want to have a state management layer, with a dependency tree, as opposed to reading from the db every time the widget is built.

The way I understand it is that you want to have state management with the provider package, but you don't want to create types that extend ChangeNotifier to manage your data models.
You gonna have to extend ChnageNotifier in order to call notifyListeners where needed to update your UI. So at least create one type that extends ChangeNotifier, and have it manage all of your data objects. Generally, this is not a good as there is no reason not to create a type per each model.

Related

Flutter RiverPod - loading data from multiple repositories required for a form

A RiverPod newbie question... I am looking for design guidance on how to use RiverPod providers for a Flutter form where I need to load....
The data entity being updated in the form
A list of another entities that are used as the data source for a drop down selector
A second list of a third entity that again will be used to populate a drop down selector
Should I design this around a composite state class that includes data for all three sources?
Or should there be a separate FutureProvider for each data source? If so, how would I combine the three into one 'Future' ?

flutter, provider and data tables

I'm looking for a way to create a data table with flutter driven by the provider package. But whatever I try with Table() or DataTable() I can't make it happen to connect to a ChangeNotificationProvider.
Both TableRow and DataRaw are not widgets I can connect to the provider.
I want to achieve a way to the each object from my business model connected to a row in the table.
When a value is changing I don't want to rebuild the whole table (that I could achieve with DateTable). I want to update only the relevant cells and keep the scroll position.
Any hint ? All the samples I could find or build are not really useful for reality.

How to pass data from one class to another while making it mutable in Flutter?

I am new to Flutter. As of now when I pass data between Stateful Classes the data becomes immutable for the receiving class. This should help be re-render widgets in both classes whenever ever one class updates the data.
How does inheritance work in flutter so that I can make data mutable between classes ? Can someone explain this with a sample code example.

How to update the state of two independent components in react-native?

Update state of two independent components in react-native.
For example I have two components like contributorOne and contributorTwo, based on some event happening in contributorOne I want to update the state of contributorTwo data.
There is no parent child relationship in contributorOne and contributorTwo components, so can anyone help me with this.
You might want to explore an option such as Redux or another form of a flux architecture, which keeps a global state instead of using a per-component state. That way, when an action occurs in one component, it can dispatch an update to the global state which the other component can be subscribed to. There is no necessity for a shared parent relationship in this architecture, either, which seems to fit your requirements.

Need some advice concerning MVVM + Lightweight objects + EF

We develop the back office application with quite large Db.
It's not reasonable to load everything from DB to memory so when model's proprties are requested we read from DB (via EF)
But many of our UIs are just simple lists of entities with some (!) properties presented to the user.
For example, we just want to show Id, Title and Name.
And later when user select the item and want to perform some actions the whole object is needed. Now we have list of items stored in memory.
Some properties contain large textst, images or other data.
EF works with entities and reading a bunch of large objects degrades performance notably.
As far as I understand, the problem can be solved by creating lightweight entities and using them in appropriate context.
First.
I'm afraid that each view will make us create new LightweightEntity and we eventually will end with bloated object context.
Second. As the Model wraps EF we need to provide methods for various entities.
Third. ViewModels communicate and pass entities to each other.
So I'm stuck with all these considerations and need good architectural design advice.
Any ideas?
For images an large textst you may consider table splitting, which is commonly used to split a table in a lightweight entity and a "heavy" entity.
But I think what you call lightweight "entities" are data transfer objects (DTO's). These are not supplied by the context (so it won't get bloated) but by projection from entities, which is done in a repository or service.
For projection you can use AutoMapper, especially its newer feature that I describe here. This allows you to reduce the number of methods you need to provide "for various entities" (DTO's), because the type to project to can be given in a generic type parameter.