Skip to content

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:

$ xc init

This will:

  1. Update pubspec.yaml — adds xwidget as a dependency and xwidget_builder as a dev dependency, fetching the latest versions from pub.dev automatically.
  2. Register asset directories — adds resources/fragments/ and resources/values/ to the flutter.assets section.
  3. Run flutter pub get — resolves all dependencies.
  4. Create directories:
    • lib/xwidget/controllers/ — for custom controller classes
    • resources/fragments/ — for XML UI fragment files
    • resources/values/ — for XML value resource files (colors, strings, etc.)
  5. Copy starter files:
    • .xwidget/xwidget_config.yaml — code generator configuration
    • lib/xwidget/inflater_spec.dart — inflater specification
    • lib/xwidget/icon_spec.dart — icon specification
    • resources/values/colors.xml — color value definitions
    • resources/values/strings.xml — string value definitions
  6. Run code generationinit finishes by running xc 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:

$ xc init --new-app

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:

  1. Define your inflater spec — edit lib/xwidget/inflater_spec.dart to list the Flutter widgets your app uses. See Inflaters.
  2. Define your icon spec — edit lib/xwidget/icon_spec.dart to list the icons your app uses. See Icons.
  3. Regenerate — after editing the specs, run xc generate to regenerate inflaters, controllers, and icons. See Code Generation Overview.
  4. Build your UI — create XML fragments in resources/fragments/ to define your UI layout.