flutter_smartgen 0.5.0
flutter_smartgen: ^0.5.0 copied to clipboard
CLI that scaffolds Flutter feature-module pages with GetX, registers routes, syncs AppImages, creates environment files, and scaffolds lib/app. Configure via smartgen.yaml.
flutter_smartgen #
CLI for Flutter apps using GetX. Scaffolds feature-module pages, registers routes, and syncs AppImages from asset folders.
Run from your Flutter project root (pubspec.yaml + lib/).
Quick start #
smartgen init
smartgen page profile --route
smartgen assets images
What you get
smartgen.yaml— project configlib/screens/profile_screen/— 6 files (view, controller, binding, repository, model, barrel)lib/router/app_routes.dart+app_pages.dart— route constant +GetPage(created if missing)lib/app/app_images.dart— asset constants from your folders
Build your UI inside _mainBody() in the generated view.
Examples #
Run smartgen page profile --route in a project named my_app.
Page module (lib/screens/profile_screen/) #
profile_screen/
├── profile.dart # barrel exports
├── binding/profile_screen_binding.dart
├── controller/profile_screen_controller.dart
├── resource/
│ ├── model/profile_model.dart
│ └── repository/profile_screen_repository.dart
└── view/profile_screen.dart
view/profile_screen.dart
class ProfileScreen extends GetView<ProfileController> {
const ProfileScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: _mainBody(context),
);
}
Widget _mainBody(BuildContext context) {
return const SizedBox(); // add your UI here
}
}
binding/profile_screen_binding.dart
class ProfileScreenBinding extends Bindings {
@override
void dependencies() {
Get
..lazyPut<ProfileScreenRepository>(ProfileScreenRepository.new)
..lazyPut<ProfileController>(
() => ProfileController(Get.find<ProfileScreenRepository>()),
);
}
}
Routes (--route or smartgen route profile) #
lib/router/app_routes.dart — constant appended:
class AppRoutes {
AppRoutes._();
static const String profilePage = '/profile';
}
lib/router/app_pages.dart — imports + GetPage appended:
import 'package:my_app/screens/profile_screen/binding/profile_screen_binding.dart';
import 'package:my_app/screens/profile_screen/view/profile_screen.dart';
class AppPages {
AppPages._();
static final List<GetPage<dynamic>> getPages = <GetPage<dynamic>>[
GetPage<dynamic>(
name: AppRoutes.profilePage,
binding: ProfileScreenBinding(),
page: () => const ProfileScreen(),
),
];
}
If lib/router/ does not exist, the first route command creates these files automatically.
AppImages (smartgen assets images) #
Given assets/images/ic_back.svg and assets/icons/search_icon.svg in your yaml directories:
lib/app/app_images.dart
class AppImages {
AppImages._();
/// Images
static const String icBack = 'assets/images/ic_back.svg';
/// Icons
static const String searchIcon = 'assets/icons/search_icon.svg';
}
Re-runs add new files, skip existing constants, and remove entries when the asset file was deleted.
Environment files (smartgen env) #
.env.development and .env.production (project root):
# Generated by smartgen env — add real values locally; do not commit secrets.
BASE_URL=
API_KEY=
Add both files to .gitignore. Load with flutter_dotenv if needed.
App folder (smartgen app) #
Creates lib/app/ scaffold files (skip if exist). All files or one by name:
smartgen app
smartgen app fonts
smartgen app class
app_class.dart — singleton with default loading state:
class AppClass {
factory AppClass() => _singleton;
AppClass._internal();
static final AppClass _singleton = AppClass._internal();
RxBool isLoading = false.obs;
}
Other files (AppColors, AppConstants, AppStrings, …) are empty class shells. Run smartgen assets images to fill AppImages.
Valid names: barrel, colors, constants, strings, images, fonts, lists, enum, dialogue, class, translation.
Install #
Global (any project)
dart pub global activate flutter_smartgen
export PATH="$PATH:$HOME/.pub-cache/bin" # add to ~/.zshrc or ~/.bash_profile
Windows or issues? Set up your path.
Dev dependency (recommended for teams)
dev_dependencies:
flutter_smartgen: ^0.5.0
dart pub get
dart run flutter_smartgen:smartgen init
Important: With a dev dependency, always use
dart run flutter_smartgen:smartgen …— notsmartgen ….Example:
dart run flutter_smartgen:smartgen page profile --route
Commands #
| Command | Description |
|---|---|
smartgen init |
Create smartgen.yaml |
smartgen env |
Create .env.development and .env.production (skip if exist) |
smartgen app [name] |
Create lib/app/ scaffold files (all or one: fonts, colors, …) |
smartgen page <name> |
Generate a screen module (6 files) |
smartgen page <name> --route |
Generate module + register route |
smartgen route <name> |
Register route only (module must exist) |
smartgen assets images |
Sync AppImages from asset folders |
Existing page, env, and app files are never overwritten. Re-runs skip what already exists.
Configuration #
smartgen init writes smartgen.yaml:
package_name: my_app
screens_base: lib/screens
naming:
screen_suffix: Screen
controller_suffix: Controller
routes:
routes_file: lib/router/app_routes.dart
pages_file: lib/router/app_pages.dart
routes_class: AppRoutes
pages_class: AppPages
route_name_suffix: Page
assets:
images:
output: lib/app/app_images.dart
class_name: AppImages
directories:
- assets/images
Optional: uncomment common_scaffold in yaml to use your shared scaffold instead of Scaffold.
For assets images: add files under assets/images, list folders in pubspec.yaml → flutter: assets:, then run the command. New files are added, deleted files are removed from AppImages.
Naming #
| Input | Module folder | Route constant | Path |
|---|---|---|---|
profile |
profile_screen/ |
profilePage |
/profile |
sign_up |
sign_up_screen/ |
signUpPage |
/sign_up |
Classes use your naming suffixes (default: ProfileScreen, ProfileController).
Support #
Open an issue on GitHub.
Author #
License #
MIT — see LICENSE.