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.
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
- 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);
}No ADS
FlutterArtist
- Basic concepts in Flutter Artist
- FlutterArtist Block ex1
- FlutterArtist Form ex1
- FlutterArtist FormModel.patchFormFields() Ex1
- FlutterArtist BlockQuickItemUpdateAction Ex1
- FlutterArtist BlockNumberPagination Ex1
- FlutterArtist BlockQuickMultiItemCreationAction Ex1
- FlutterArtist ListView Infinite Scroll Pagination Example
- FlutterArtist Pagination
- FlutterArtist Sort DropdownSortPanel Example
- FlutterArtist Dio
- FlutterArtist BackgroundWebDownloadAction ex1
- FlutterArtist Block External Shelf Event ex1
- FlutterArtist Master-detail Blocks ex1
- FlutterArtist Scalar ex1
- FlutterArtist Pagination Davi table Infinite Scroll Ex1
- FlutterArtist Filter FormBuilderField ex1
- FlutterArtist Form Parent-child MultiOptFormProp ex1
- FlutterArtist Manual Sorting ReorderableGridView Example
- FlutterArtist Manual Sorting ReorderableListView
- FlutterArtist Scalar External Shelf Event ex1
- FlutterArtist Log Viewer
- FlutterArtist config
- FlutterArtist StorageStructure
- FlutterArtist Debug Storage Viewer
- FlutterArtist DebugMenu
- FlutterArtist Context Provider Views
- FlutterArtist Internal Shelf Event ex1
- FlutterArtist Deferring External Shelf Events (Ex1)
- FlutterArtist DropdownSortPanel
Show More