mydomain
No ADS
No ADS

FlutterArtist StorageStructure

  1. registerShelves()
  2. registerActivities()
  3. defineProjectionFamilies()
As mentioned in the introduction, FlutterArtist creates a scene similar to walking into a warehouse filled with stocked shelves. For such a system to function, you must declare a StorageStructure. Below is a simple storage structure from the FlutterArtist Demo.
MyDemoStorageStructure
class MyDemoStorageStructure extends StorageStructure {
  @override
  void registerActivities() {
    FlutterArtist.storage.registerActivity(() => AppLoginActivity());
  }

  @override
  void registerShelves() { 
    FlutterArtist.storage.registerShelf(() => Country61aShelf()); 
    FlutterArtist.storage.registerShelf(() => FootballPlayer86aShelf());
    FlutterArtist.storage.registerShelf(() => ProjectContributor98aShelf());
    // ...
  } 
  
  @override
  List<ProjectionFamily> defineProjectionFamilies() {
    return [
      ProjectionFamily<int>(
        familyName: 'supplier-projections',
        members: {SupplierInfo, SupplierData},
      ),
      ProjectionFamily<int>(
        familyName: 'album-projections',
        members: {AlbumInfo, AlbumData},
      ),
      ProjectionFamily<int>(
        familyName: 'company-projections',
        members: {CompanyInfo, CompanyData, CompanyTreeItem, CompanyTree},
      ), 
      // ...
    ];
  } 
}
You need to register your StorageStructure class with the application by calling the FlutterArtist.config() method in main.dart.
main.dart (*)
await FlutterArtist.config(
  storageStructure: MyDemoStorageStructure(),
  ...
);
No ADS
Notably, to verify if your "warehouse" is organized as intended, you can use the Debug Storage Viewer. This is a powerful tool that allows you to visually inspect your StorageStructure, track active Shelf(s), and monitor real-time data.
  • Giới thiệu về FlutterArtist
Requiring structure registration through StorageStructure might seem strict, but it's how FlutterArtist protects you from "ghost bugs" during development. It creates a Single Source of Truth, where you can look and know exactly what your application contains.
The combination of this strict registration and the visibility provided by the Debug Storage Viewer turns state management from a headache into a controlled and enjoyable experience.

1. registerShelves()

The registerShelves() method allows you to register Shelf(s). Imagine having shelves that need to be placed in the correct positions within the warehouse before they can be used.
registerShelves()
@override
void registerShelves() { 
   FlutterArtist.storage.registerShelf(() => Country61aShelf()); 
   FlutterArtist.storage.registerShelf(() => FootballPlayer86aShelf());
   FlutterArtist.storage.registerShelf(() => ProjectContributor98aShelf());
} 
Anywhere in the application, you can access any shelf by searching for it within the storage.
FootballPlayer86aShelf shelf = FlutterArtist.storage.findShelf();
If a Shelf is not registered, a runtime error will occur when you attempt to access it. A bright red error screen will appear to alert you.

2. registerActivities()

The registerActivities() method allows you to register Activity(s) — a data model and controller that simulates specific activities or functions. Essentially, an Activity is designed to handle complex logic that Block and Scalar do not cover, such as AppLoginActivity for authentication.
Note: Currently, the Activity design is in its early stages. Its scope is limited, and significant changes are expected in future versions to optimize its capabilities.
No ADS
registerActivities()
@override
void registerActivities() {
  FlutterArtist.storage.registerActivity(() => AppLoginActivity());
}
Similar to a Shelf, accessing an unregistered Activity will trigger a red screen error.
findActivity()
AppLoginActivity loginActivity = FlutterArtist.storage.findActivity();

3. defineProjectionFamilies()

The defineProjectionFamilies() method allows you to define ProjectionFamily(s). This is a core concept that helps manage different data versions of the same entity.
  • FlutterArtist Projections (***)
defineProjectionFamilies()
@override
List<ProjectionFamily> defineProjectionFamilies() {
  return [
    ProjectionFamily<int>(
      familyName: 'supplier-projections',
      members: {SupplierInfo, SupplierData},
    ),
    ProjectionFamily<int>(
      familyName: 'album-projections',
      members: {AlbumInfo, AlbumData},
    ),
    ProjectionFamily<int>(
      familyName: 'company-projections',
      members: {CompanyInfo, CompanyData, CompanyTreeItem, CompanyTree},
    ), 
    // ...
  ];
} 
No ADS
No ADS