flutter_smartgen 0.1.1 copy "flutter_smartgen: ^0.1.1" to clipboard
flutter_smartgen: ^0.1.1 copied to clipboard

CLI that scaffolds Flutter feature-module pages with GetX: barrel, binding, controller, repository, model, and view. Configure paths via smartgen.yaml.

flutter_smartgen #

pub package License

A Dart CLI that scaffolds Flutter feature-module pages with a consistent GetX architecture — barrel file, binding, controller, repository, model, and view — so your team can add new screens in seconds with the same folder layout every time.

Run smartgen init once, then smartgen page <name> from any Flutter project root. Global activation is optional if you add the package as a dev dependency.


Features #

  • Project setupsmartgen init creates smartgen.yaml from your pubspec.yaml package name
  • Page scaffoldingsmartgen page <name> generates six Dart files per screen module
  • GetX-readyGetView, GetxController, Bindings, and Get.lazyPut out of the box
  • Flexible scaffold — use your shared CommonScaffold or default Flutter Scaffold
  • Safe re-runs — existing files are never overwritten
  • Clean views — generated screens use _mainBody() with a SizedBox() placeholder

Installation #

Use either option below. You do not need both.

Option 1 — Global activate (CLI everywhere) #

dart pub global activate flutter_smartgen

If smartgen is not found, add the pub cache to your PATH:

macOS / Linux

export PATH="$PATH:$HOME/.pub-cache/bin"

Windows (PowerShell)

$env:Path += ";$env:LOCALAPPDATA\Pub\Cache\bin"

Verify:

smartgen --help

Run from any Flutter project:

smartgen init
smartgen page profile

Option 2 — Project dev dependency (no global activate) #

Add to your Flutter app pubspec.yaml:

dev_dependencies:
  flutter_smartgen: ^0.1.0

Install and run via dart run:

dart pub get
dart run flutter_smartgen:smartgen init
dart run flutter_smartgen:smartgen page profile

No PATH setup required. Recommended for teams so everyone uses the same version from pubspec.lock.


Quick start #

From your Flutter app root (where pubspec.yaml and lib/ exist):

Global CLI

smartgen init
smartgen page profile

Project dev dependency

dart run flutter_smartgen:smartgen init
dart run flutter_smartgen:smartgen page profile

This creates:

lib/screens/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             # GetView screen UI

Wire the new screen in your router (GetPage + binding), then build your UI inside _mainBody().


Configuration #

smartgen init creates smartgen.yaml in your project root.

package_name: my_app
screens_base: lib/screens

# Optional — use CommonScaffold instead of Scaffold in generated views
common_scaffold:
  import: package:my_app/widgets/common_scaffold.dart
  class_name: CommonScaffold

naming:
  screen_suffix: Screen
  controller_suffix: Controller
Key Required Description
package_name Yes Dart package name used in generated imports
screens_base Yes Base path for screen modules (e.g. lib/screens)
common_scaffold No import and class_name for a shared scaffold widget
naming No Class name suffixes for screen and controller

Each page is generated at lib/screens/{name}_screen/ under screens_base.


Generated code #

View — scaffold + empty body:

class ProfileScreen extends GetView<ProfileController> {
  @override
  Widget build(BuildContext context) {
    return CommonScaffold( // or Scaffold when common_scaffold is not set
      body: _mainBody(context),
    );
  }

  Widget _mainBody(BuildContext context) {
    return const SizedBox();
  }
}

Controller — repository injection + onInit:

class ProfileController extends GetxController {
  ProfileController(this.repository);

  late ProfileScreenRepository repository;

  @override
  void onInit() {
    super.onInit();
  }
}

Binding — lazy dependency registration:

Get
  ..lazyPut<ProfileScreenRepository>(ProfileScreenRepository.new)
  ..lazyPut<ProfileController>(
    () => ProfileController(Get.find<ProfileScreenRepository>()),
  );

Commands #

Command (global) Command (dev dependency) Description
smartgen init dart run flutter_smartgen:smartgen init Create smartgen.yaml (skipped if file exists)
smartgen page <name> dart run flutter_smartgen:smartgen page <name> Generate a screen module (requires smartgen.yaml)

Naming conventions #

Input Folder Barrel file View file
profile profile_screen/ profile.dart view/profile_screen.dart
demo demo_screen/ demo.dart view/demo_screen.dart

Class names follow your naming config (default: ProfileScreen, ProfileController, ProfileScreenRepository).


Support #

For bugs, feature requests, or questions, open an issue on GitHub.


Author #

Kishan
Kishan

License #

This project is licensed under the MIT License — see the LICENSE file for details.

3
likes
0
points
59
downloads

Publisher

unverified uploader

Weekly Downloads

CLI that scaffolds Flutter feature-module pages with GetX: barrel, binding, controller, repository, model, and view. Configure paths via smartgen.yaml.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

args, path, yaml

More

Packages that depend on flutter_smartgen