-
Notifications
You must be signed in to change notification settings - Fork 0
Utilities
Shared widgets live in:
lib/widgets/
The goal is to keep page modules small and avoid duplicating UI components across features.
- Buttons:
app_button.dart - Icon button:
app_icon_button.dart - Search bar:
app_search_bar.dart - Segmented control:
app_segmented_triple_control.dart - Scroll-to-top FAB:
scroll_to_top_button.dart
If a widget is only used by a single feature, keep it inside that feature folder instead.
This repository is a Flutter app template that demonstrates a lightweight, layered structure you can copy for new features.
-
lib/core/- Cross-cutting concerns (app scope, settings, themes, etc.).
-
lib/core/injection.dart- Dependency injection wiring (GetIt).
-
lib/l10n/- Generated localization code (see the Localization page).
-
lib/pages/- Feature modules. In this app they are
page1topage6. - Each module demonstrates a layered approach:
-
*_datasource.dartfor I/O (API, DB, etc.) -
*_repository.dartfor domain-friendly access -
*_usecases.dartfor orchestration / business rules -
*_entity.dartfor immutable data models -
*_page.dartfor UI
-
- Feature modules. In this app they are
-
lib/widgets/- Shared widgets used across multiple pages (buttons, search bar, etc.).
OpenPlant uses GetIt for dependency injection, wired in one place:
-
lib/core/injection.dartregisters datasources, repositories, and usecases, and buildsAppServices. -
lib/main.dartcallsinit()at startup. -
lib/core/app_scope.dartexposesSettingsControllerandAppServicesto the widget tree (so pages stay free of plugin imports).
Pages access services via:
AppScope.of(context).services.pageN
For the full architecture description, see Architecture.
The template uses Flutter's built-in gen-l10n system with .arb files.
assets/l10n/l10n_en.arbassets/l10n/l10n_de.arb
Configuration:
l10n.yaml
Generated output:
lib/l10n/l10n.dartlib/l10n/l10n_en.dartlib/l10n/l10n_de.dart
Use the BuildContext extension:
lib/l10n/l10n_x.dart
Example:
Text(context.l10n.page1Title)- Add the key to all supported locales in
assets/l10n/. - Re-run localization generation (for example
flutter gen-l10norflutter runwhich triggers generation). - Use the new key via
context.l10n.<key>.
The template keeps UI state in memory but persists user settings to local storage.
lib/core/settings.dart
SettingsController loads its initial state once at startup and persists updates via shared_preferences.
The Settings model is serialized to JSON and includes (at minimum):
- Theme mode flags
- Text scaling preference
- Onboarding completion flag (
didCompleteOnboarding) - Selected language (
localeCode) ornullfor system language
JSON keeps the migration story simple for a template:
- Add a new field with a default in
Settings.fromJson(...) - Old installs continue to load