Project Initialization
The init command bootstraps an existing Flutter project for XWidget development. It
configures dependencies, creates the required directory structure, and copies starter files.
Initialize an Existing Project
Run from your Flutter project root:
This will:
- Update
pubspec.yaml— addsxwidgetas a dependency andxwidget_builderas a dev dependency, fetching the latest versions from pub.dev automatically. - Register asset directories — adds
resources/fragments/andresources/values/to theflutter.assetssection. - Run
flutter pub get— resolves all dependencies. - Create directories:
lib/xwidget/controllers/— for custom controller classesresources/fragments/— for XML UI fragment filesresources/values/— for XML value resource files (colors, strings, etc.)
- Copy starter files:
.xwidget/xwidget_config.yaml— code generator configurationlib/xwidget/inflater_spec.dart— inflater specificationlib/xwidget/icon_spec.dart— icon specificationresources/values/colors.xml— color value definitionsresources/values/strings.xml— string value definitions
- Run code generation —
initfinishes by runningxc generate, so the generated inflaters, controllers, icons, and registry already exist when it completes.
Create a New XWidget App
To scaffold a complete XWidget app with a working example:
This performs everything above, plus:
- Creates
lib/main.dart— a working entry point configured for XWidget - Creates
lib/xwidget/controllers/app_controller.dart— an example controller - Creates
resources/fragments/my_app.xml— an example XML fragment - Creates
resources/fragments/count.xml— a second example XML fragment
Warning
The --new-app flag will overwrite your existing lib/main.dart and other files.
You will be prompted to confirm before proceeding.
Options
| Option | Abbr | Description |
|---|---|---|
--new-app |
-n |
Scaffold a complete XWidget app with examples |
--no-logo |
Suppress the XWidget logo output |
After Initialization
Once initialization is complete:
- Define your inflater spec — edit
lib/xwidget/inflater_spec.dartto list the Flutter widgets your app uses. See Inflaters. - Define your icon spec — edit
lib/xwidget/icon_spec.dartto list the icons your app uses. See Icons. - Regenerate — after editing the specs, run
xc generateto regenerate inflaters, controllers, and icons. See Code Generation Overview. - Build your UI — create XML fragments in
resources/fragments/to define your UI layout.