flutter_smartgen 0.3.0
flutter_smartgen: ^0.3.0 copied to clipboard
CLI that scaffolds Flutter feature-module pages with GetX and generates AppImages from asset folders. Configure paths 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.
Install #
Global (any project)
dart pub global activate flutter_smartgen
export PATH="$PATH:$HOME/.pub-cache/bin" # add to shell profile if needed
Dev dependency (recommended for teams)
dev_dependencies:
flutter_smartgen: ^0.3.0
dart pub get
dart run flutter_smartgen:smartgen init
Use dart run flutter_smartgen:smartgen … instead of smartgen … when installed as a dev dependency.
Commands #
| Command | Description |
|---|---|
smartgen init |
Create smartgen.yaml |
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 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.