Skip to content

Registry

The registry simplifies initialization. Instead of manually calling registration functions and applying configuration values, pass a single generated function to XWidget.initialize(). The framework registers everything and applies your configuration automatically, and the generator keeps the registry in sync — add a widget to your inflater spec, regenerate, and the change flows through without touching main.dart.

What Gets Generated

lib/xwidget/generated/registry.g.dart contains a single public function, registerXWidgetComponents(). It looks approximately like this:

// GENERATED CODE - DO NOT MODIFY BY HAND
import 'package:xwidget/xwidget.dart';

import 'inflaters.g.dart';
import 'icons.g.dart';
import 'controllers.g.dart';

void registerXWidgetComponents() {
   XWidget.config = const XWidgetConfig(
      fragmentsPath: 'resources/fragments',
      valuesPath: 'resources/values',
   );
   registerXWidgetIcons();
   registerXWidgetInflaters();
   registerXWidgetControllers();
}

The actual contents reflect your project's configuration — paths come from xwidget_config.yaml, and the three registration calls are emitted in the order the builder produces them.

How It's Called

XWidget.initialize() calls the register callback before loading resources. The typical main():

import 'package:xwidget/xwidget.dart';
import 'xwidget/generated/registry.g.dart';

void main() async {
   WidgetsFlutterBinding.ensureInitialized();

   await XWidget.initialize(register: registerXWidgetComponents);

   runApp(MyApp());
}

The register callback is technically optional — you can still call the three per-component registrations yourself if you want fine-grained control — but there is rarely a reason to.

Where to Configure Paths

Configure fragmentsPath and valuesPath in xwidget_config.yaml. See Custom Local Paths for runtime overrides.

Constructor arguments to LocalResources / CloudResources take precedence over xwidget_config.yaml.

Regeneration Behavior

The registry is always regenerated, even when you pass --only inflaters or another subset to xc generate. This ensures the registry stays in sync with whatever mix of per-component files is on disk.

The output location is configurable via the registry.target key in xwidget_config.yaml (default: lib/xwidget/generated/registry.g.dart). Registry generation is skipped when the project's xwidget dependency is below 0.5.0, which predates the registry.

See Code Generation Overview for the full generator options.