FlutterArtist config
FlutterArtist.config() is a crucial method for configuring the FlutterArtist application. This method must be called before the app starts via Flutter's runApp() function. Below is a code snippet illustrating how to implement it.
main.dart
Future<void> initGlobalsDependencies() async {
await FlutterArtist.config(
storageStructure: MyDemoStorageStructure(),
// Other properties
);
// Initialize your other dependencies
}
Future<void> main() async {
await initGlobalsDependencies();
//
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// Other codes
}Let’s examine an example of how FlutterArtist.config() is used in the FlutterArtist Demo, then we will analyze its core components in detail.
FlutterArtist.config()
await FlutterArtist.config(
storageStructure: MyDemoStorageStructure(),
coreFeaturesAdapter: GetxFlutterArtistCoreFeaturesAdapter(),
localeAdapter: GetxFlutterArtistLocaleAdapter(
supportedLocales: const [Locale("en", "US"), Locale("vi", "VN")],
),
notificationAdapter: NotificationAdapterImpl(),
loginLogoutAdapter: LoginLogoutAdapterImpl(),
globalDataAdapter: GlobalDataAdapterImpl(),
showRestDebugDialog: (BuildContext context) {
bool isSystemUser = FlutterArtist.loggedInUser?.isSystemUser ?? false;
showRestDebugDialog(
context,
showJson: isSystemUser,
showToken: isSystemUser,
);
},
maxStoredLogEntryCount: 20,
notificationFetchPeriodInSeconds: 24 * 60 * 60,
codeFlowRetentionPeriodInSeconds: 20,
debugOptions: DebugOptions(),
consoleDebugOptions: ConsoleDebugOptions(
enabled: true,
navigatorObserver: false,
routeAware: false,
globalManager: false,
dataLoad: false,
),
);1. coreFeaturesAdapter
FlutterArtist was initially built upon the accessible features provided by GetX, such as Global BuildContext, Overlay, and SnackBar. Among these, the Overlay is a nearly transparent layer covering the entire screen, used to temporarily prevent user interaction with underlying widgets until an asynchronous task is completed.
However, to prevent FlutterArtist users from being forced into a dependency on GetX, the FlutterArtistCoreFeaturesAdapter interface was designed as an intermediate abstraction layer. This solution allows for the removal of direct dependency on GetX, while core features like Overlay and SnackBar can still be provided through different implementation mechanisms.
No ADS
If you choose to use FlutterArtist alongside GetX, you won't need to write your own implementation for this interface. Instead, the library provides the GetxFlutterArtistCoreFeaturesAdapter class within the flutter_artist_getx_adapter extension package.
FlutterArtist.config(
coreFeaturesAdapter: GetxFlutterArtistCoreFeaturesAdapter(),
...
);pubspec.yaml
dependencies:
flutter_artist_getx_adapter: To understand the different implementations of GetxFlutterArtistCoreFeaturesAdapter in detail, you can refer to the technical documentation at the link below.
- FlutterArtist FlutterArtistCoreFeaturesAdapter
2. localeAdapter
In the Flutter ecosystem, there are many libraries that support building multi-language applications, such as GetX, Slang, or easy_localization. Each library has its own way of handling language updates on the UI. To ensure flexibility and "fairness" for any developer choice, FlutterArtist does not directly interfere with this logic but instead uses an intermediate layer called FlutterArtistLocaleAdapter.
FlutterArtistLocaleAdapter
interface class FlutterArtistLocaleAdapter {
List<Locale> supportedLocales() {
throw UnimplementedError();
}
///
/// Use this locale, for example in GETX:
/// ```dart
/// Get.updateLocale(locale);
/// ```
///
Future<void> updateLocale(Locale locale) {
throw UnimplementedError();
}
}FlutterArtist provides several common Adapters that you can use immediately:
- GetxFlutterArtistLocaleAdapter
- SlangFlutterArtistLocaleAdapter
No ADS
- FlutterArtist FlutterArtistLocaleAdapter (***)
You need to register your FlutterArtistLocaleAdapter in FlutterArtist.config(). For example:
await FlutterArtist.config(
...
localeAdapter: GetxFlutterArtistLocaleAdapter(
supportedLocales: const [Locale("en", "US"), Locale("vi", "VN")],
),
);How to retrieve the list of supported Locale(s) to display on the language selection UI:
List<Locale> locales = FlutterArtist.localeAdapter.supportedLocales();How FlutterArtist updates the UI when the user changes the language:
void _onLocaleChanged(Locale selectedLocale) {
// Update via registered adapter.
FlutterArtist.localeAdapter.updateLocale(selectedLocale);
}3. loginLogoutAdapter
The core purpose of FlutterArtistLoginLogoutAdapter is to define how to convert an ILoggedInUser object into a JSON string and vice versa. This JSON data is persistently stored by FlutterArtist on the local device (Local Storage). During subsequent app launches, this JSON string is read back to immediately extract the authentication Token. This is key to implementing a seamless Auto-login mechanism.
Specifically, the Token extracted from local storage serves as a "probe" when calling the GlobalData API. If fetching GlobalData is successful, it confirms the Token is still valid, and the app continues to operate. Conversely, if the API returns an authentication error, the system recognizes the expired session and requires the user to log in again from scratch to ensure security.
FlutterArtistLoginLogoutAdapter
interface class FlutterArtistLoginLogoutAdapter {
/// Convert the user object to a JSON string for local storage.
String toJson(ILoggedInUser loggedInUser) {
throw UnimplementedError();
}
/// Restore the user object from a JSON string upon application restart.
ILoggedInUser? fromJson(String json) {
throw UnimplementedError();
}
///
/// Implementation Example (Use with fresh_dio library):
///
/// ```
/// LoggedInUserData token = loggedInUser as LoggedInUserData;
/// fresh.setToken(token);
/// ```
///
void addThirdPartyLogicOnLogin(ILoggedInUser loggedInUser) {
throw UnimplementedError();
}
///
/// Implementation Example (Use with fresh_dio library):
///
/// ```
/// fresh.setToken(null);
/// ```
///
void addThirdPartyLogicOnLogout() {
throw UnimplementedError();
}
}Additionally, this Adapter provides two strategic hooks: addThirdPartyLogicOnLogin and addThirdPartyLogicOnLogout. This is where you can easily and cleanly integrate logic with third-party Token management libraries like fresh_dio.
If you are using FlutterArtist in conjunction with fresh_dio, here is an example of how to implement this interface:
LoginLogoutAdapterImpl
class LoginLogoutAdapterImpl implements FlutterArtistLoginLogoutAdapter {
@override
ILoggedInUser? fromJson(String json) {
Map<String, dynamic> map = jsonDecode(json);
return LoggedInUserData.fromJson(map);
}
@override
String toJson(ILoggedInUser loggedInUserData) {
// Cast to your specific data model
LoggedInUserData data = loggedInUserData as LoggedInUserData;
return jsonEncode(data.toJson());
}
@override
void addThirdPartyLogicOnLogin(ILoggedInUser loggedInUser) {
// LoggedInUserData implements OAuth2Token from the fresh_dio package:
LoggedInUserData token = loggedInUser as LoggedInUserData;
fresh.setToken(token);
}
@override
void addThirdPartyLogicOnLogout() {
// Clear the token upon logging out
fresh.setToken(null);
}
}4. globalDataAdapter
FlutterArtistGlobalDataAdapter is responsible for loading foundational and shared data across the entire application, such as branch lists, company information, personalized user settings, or system categories. This data is highly stable with low volatility but is frequently accessed across various screens.
No ADS
GlobalData will be triggered for load immediately after a user successfully logs in or during the Auto-login process.
GlobalData can also be converted into a JSON string for persistent storage on the local device. This stored version acts as a "Fallback" plan: If the app starts without an internet connection, FlutterArtist recreates GlobalData from the local JSON to ensure the user can still view basic information (except when the Token has expired and requires re-authentication).
FlutterArtistGlobalDataAdapter
interface class FlutterArtistGlobalDataAdapter<G extends IGlobalData> {
// Implement data load from the server via ILoggedInUser (containing a token).
Future<G> performLoadGlobalData({required ILoggedInUser loggedInUser}) async {
throw UnimplementedError();
}
// Convert global data to JSON for local storage.
String toJson(G globalData) {
throw UnimplementedError();
}
// Recreate global data from a saved JSON string.
G? fromJson(String json) {
throw UnimplementedError();
}
}5. maxStoredLogEntryCount
maxStoredLogEntryCount defines the maximum number of LogEntry records kept for display in the Debug Log Viewer. Once this limit is reached, the oldest entries are automatically discarded to make room for new data, optimizing memory during the debugging process. The default value is 20.
6. codeFlowRetentionPeriodInSeconds
Debug Code Flow Viewer is an advanced debugging feature of FlutterArtist. It is specifically designed for the Platform Developer to have absolute control over the code flow. By explicitly specifying each Line-Code-Id (e.g., #11111, #22222), if an error occurs, you can simply search for that unique identifier to instantly navigate to the exact line of code in the original source.
Additionally, this tool provides significant support for Application Developers using the library, helping them visually observe the execution path and understand how the system operates.
The CodeFlow manager stores a list of ExecutionTrace(s), where each ExecutionTrace contains multiple TraceStep(s).
codeFlowRetentionPeriodInSeconds specifies the number of seconds an ExecutionTrace is retained in the list once new ExecutionTrace are added. This means when a new execution flow appears, the system will clean up elements older than the specified seconds (default is 20 seconds). If no new traces are added, existing records remain for analysis.
No ADS
FlutterArtist
- Basic concepts in Flutter Artist
- FlutterArtist Block ex1
- FlutterArtist Filter Example
- FlutterArtist FilterModel MultiOptFilterCriterion ex1
- FlutterArtist FilterInput Example 1
- FlutterArtist Form ex1
- The idea of designing filter models in FlutterArtist
- FlutterArtist FormModel.patchFormFields() Ex1
- FlutterArtist BlockQuickItemUpdateAction Example
- FlutterArtist BlockNumberPagination Ex1
- FlutterArtist GridView Infinite Scroll Example
- FlutterArtist BlockQuickMultiItemCreationAction Example
- FlutterArtist ListView Infinite Scroll Pagination Example
- FlutterArtist Pagination
- FlutterArtist Sort DropdownSortPanel Example
- FlutterArtist Dio
- FlutterArtist BlockBackendAction Example
- FlutterArtist BackgroundWebDownloadAction Example
- FlutterArtist StorageBackendAction ex1
- FlutterArtist Block External Shelf Event ex1
- FlutterArtist Filter FormBuilderMultiDropDown Ex1
- FlutterArtist Master-detail Blocks ex1
- FlutterArtist Scalar ex1
- FlutterArtist Pagination Davi table Infinite Scroll Ex1
- FlutterArtist Filter Tree FormBuilderField ex1
- FlutterArtist Filter FormBuilderRadioGroup ex1
- FlutterArtist Form Parent-child MultiOptFormProp ex1
- FlutterArtist Manual Sorting ReorderableGridView Example
- FlutterArtist Manual Sorting ReorderableListView
- FlutterArtist Scalar External Shelf Event ex1
- FlutterArtist Code Flow Viewer
- FlutterArtist Log Viewer
- FlutterArtist config
- FlutterArtist StorageStructure
- FlutterArtist Debug Storage Viewer
- FlutterArtist DebugMenu
- FlutterArtist Debug UI Components Viewer
- FlutterArtist Debug Shelf Structure Viewer
- FlutterArtist Context Provider Views
- FlutterArtist FilterModelStructure ex1
- FlutterArtist FilterModelStructure ex2
- FlutterArtist FilterModelStructure ex3
- FlutterArtist Internal Shelf Event ex1
- FlutterArtist Deferring External Shelf Events (Ex1)
- FlutterArtist DropdownSortPanel
Show More