Skip to content
Back to archipelago.banuacoder.com

UI, Assets & L10N

How to add a component to a Flutter UI kit ​

Free Reference for ui_kit_component: every variable, option and package it generates. Command: archipelago generate ui_kit_component

Scaffold a UI kit component with tests and a Widgetbook showcase, choose its atomic level, widget type and variants, and use the optional headless base class.

What you'll learn ​

  • Scaffolding a component with its tests and Widgetbook showcase
  • Choosing the atomic level, widget type and variants
  • Using the optional headless base class
  • Knowing what the hook wires for you

Prerequisites ​

The brick does not check that the UI kit exists. Run it in a project that has one.

Step 1: Generate a UI Component ​

bash
archipelago generate ui_kit_component

The prompts are:

  • componentName: for example Button, Card or Dialog. It is required.
  • prefix: your UI kit prefix. It is required.
  • atomicType: atoms, molecules, organisms, templates or pages
  • widgetType: stateless or stateful
  • useHeadless: true adds a behavior-only base class (default false)
  • hasVariants: style variants such as primary and secondary (default true)
  • hasSizes: size variants such as sm, md and lg (default true)
  • hasTypes: type variants such as filled and outline (default false)
  • appName: your app name

Or use a config file:

json
{
  "componentName": "Banner",
  "atomicType": "molecules",
  "widgetType": "stateless",
  "prefix": "App",
  "appName": "MyApp",
  "useHeadless": false,
  "hasVariants": true,
  "hasSizes": true,
  "hasTypes": false
}
bash
archipelago generate ui_kit_component --config banner.json

Step 2: Understand the Generated Structure ​

text
packages/my_app_ui_kit/
├── lib/src/components/molecules/banner/
│   ├── banner.dart                    # Barrel
│   ├── app_banner.dart                # The styled widget
│   ├── data/                          # Size, style and variant data classes
│   └── enums/                         # Variant, size and type enums
└── test/components/molecules/banner/
    └── banner_test.dart

apps/my_app_widgetbook/
└── lib/showcase/molecules/banner_showcase.dart

With useHeadless: true, the folder also holds headless_banner.dart. The styled widget then extends HeadlessBanner.

Step 3: Check What the Hook Wired ​

The post-generation hook:

  • adds an export to the barrel of the atomic level, such as molecules.dart
  • adds the showcase import and call inside the archipelago:widgetbook_* markers of widgetbook_app.dart
  • runs dart format on the output

Running it again changes nothing. A UI kit older than flutter_ui_kit 1.2.5 has no markers. The hook warns, and you add the showcase to widgetbook_app.dart by hand.

Step 4: The Headless Pattern ​

With useHeadless: true, the base class handles behavior such as tap, focus and state. The styled widget adds the visuals from the theme extensions. Use it for components with several variants and sizes. Leave it off for simple components.

Step 5: Use the Component ​

dart
import 'package:my_app_ui_kit/my_app_ui_kit.dart';

AppBanner(
  variant: AppBannerVariant.primary,
  size: AppBannerSize.md,
  child: Text('Welcome'),
)

Read colors, spacing and typography with context.colors, context.spacing and context.typography. Do not call Theme.of(context).

Step 6: Add a Variant ​

Add a value to the variant enum, then handle it where the widget resolves its style:

dart
enum AppBannerVariant { primary, secondary, danger }

Common Customizations ​

CustomizationWhere to Change
VariantsThe *_variant.dart enum and the style data
SizesThe *_size.dart enum and the size data
Widget typeRegenerate with another widgetType
Showcase knobsThe *_showcase.dart file

Next Steps ​