Status: Accepted (2026-06-22, Phase 5b.2 complete 2026-06-23; BcRenderer hybrid port complete 2026-06-24)
ADR-002 Section 1 menempatkan Flutter sebagai Tier C (track terpisah): "di-generate dari lapis Contract, bukan dari .lite.tsx. Dikerjakan setelah Tier A stabil." Saat ini Tier A stabil (177 komponen, 4 target, 0 failures). ADR-011 mengkonkretkan bagaimana Tier C diimplementasikan.
- Return type duality.
ThemeData(Material) danCupertinoThemeData(Cupertino) adalah tipe berbeda yang tidak saling extends. Dart tidak punya union type. Satu method factory tidak bisa return keduanya. - Consumer if-else hell. Kalau consumer harus
if (Platform.isIOS) CupertinoApp(...) else MaterialApp(...), prinsip "simple by default" gagal. - Flutter SDK lock-in di core.
ChangeNotifierdaripackage:flutter/foundation.dartmengunci reactive store ke Flutter. Kontrakstore.contract.tsmenyebut "portable" (line 111), violated jika core terikat Flutter SDK. - Runtime HSL conversion.
HSLColor.fromAHSL().toColor()menghasilkan non-const object.ColorSchemedidesain untukconst. 30+ token x 2 theme = 60+ konversi per build = GC pressure. - Contract drift. Kalau Flutter punya API berbeda dari React/RN, consumer harus belajar 2 API. Prinsip "1 code, 5 target" gagal.
- Adaptive di contract level. Kalau
.contract.tspunya mapping string per-platform (cupertino: ..., material: ...), contract membengkak dan Mitosis terganggu.
- flutter_platform_widgets (FPW) — Library yang menyediakan
PlatformApp,PlatformText,PlatformTextField, dll. Auto-pilih Cupertino di iOS/macOS, Material di lainnya. Dipakai oleh ribuan app production. - MaterialBasedCupertinoThemeData — Class bridge Flutter native untuk Material → Cupertino theme conversion.
- JsonForms / Formily — Schema-driven UI library (React) yang punya separate renderer per target. Pola: shared schema, separate renderer.
- Tamagui — Universal UI library yang punai shared token + separate per-platform implementation.
Tier C Flutter diimplementasikan via 5 keputusan konkret yang saling melengkapi:
Shared across all targets (75%):
| Layer | Source | Port mechanism |
|---|---|---|
| Token palette | packages/ui/tokens/theme.css (HSL source of truth) |
generate-flutter-tokens.mjs → bc_theme.dart (const hex) |
| API surface | *.contract.ts (props/events/methods/a11y) |
Manual port to Dart, validated by contract test |
| Reactive engine | store.ts (pure TS) |
Port to reactive_store.dart (pure Dart) |
| Schema renderer | BcRenderer.lite.tsx + UiSchema types |
Port to BcRenderer.dart + UiSchema Dart class |
Separate per Flutter (25%):
| Layer | Source | Why separate |
|---|---|---|
| Widget behavior | bc_xx.dart (hand-written P0, generator-assisted P1/P2) |
Mitosis-Flutter compiler tidak reliable (ADR-002 finding) |
Rationale: Tidak ada compiler TSX → Dart yang reliable. Tapi 4 layer infra (token, contract, reactive, schema) portable sebagai pure Dart/const. Hanya widget-level behavior yang perlu implementasi terpisah. Phase 5b generator akan stub 80% komponen sederhana dari contract; 20% kompleks (DataTable, Form, dll) hand-write sekali, pakai selamanya.
Consumer DX impact: ZERO. Consumer API 100% identik across React/RN/Vue/Flutter. Yang membayar 25% ekstra adalah library developer, bukan consumer.
generate-flutter-tokens.mjs parse theme.css HSL channel triplets, konversi ke hex sekali saat build-time, emit bc_theme.dart dengan static const Color values.
// Generated bc_theme.dart (excerpt):
class BcTheme {
static const Color primary = Color(0xFF2A4A8C);
static const Color primaryForeground = Color(0xFFFFFFFF);
// ... 30+ const colors
}Tailwind-style alpha parity via native Color.withValues() (Flutter 3.27+):
Container(color: BcTheme.primary.withValues(alpha: 0.5));Setara dengan web side hsl(var(--bc-primary) / 0.5). Tidak perlu helper custom, tidak perlu runtime HSL conversion.
Rationale:
| Alternatif | Kenapa ditolak |
|---|---|
(A) Runtime HSLColor.fromAHSL() |
Non-const, GC pressure, 60+ konversi per build. Anti-pattern di Flutter. |
| (C) Hex const + custom alpha helper | Color.withValues() sudah native sejak Flutter 3.27. Custom helper redundant. |
theme.css tetap single source of truth. Hex di bc_theme.dart derived, bukan authored. Sesuai ADR-002 Section 3.
Karena ThemeData dan CupertinoThemeData tidak bisa di-union (Dart tidak punya union type), "platform-aware" hidup di level app widget, bukan di level theme factory.
Layer 1 — BcTheme: const colors + 4 explicit factory methods (pure data):
class BcTheme {
// Const colors (compile-time, zero allocation)
static const Color primary = Color(0xFF2A4A8C);
static const Color success = Color(0xFF16A34A);
static const Color warning = Color(0xFFEAB308);
// ... 30+ const colors
// Explicit Material (for Ancodebuddy/Web/Windows/Linux or forced Material)
static ThemeData materialLight() => ThemeData(
colorScheme: ColorScheme.light(primary: primary, /* ... */),
useMaterial3: true,
);
static ThemeData materialDark() => ThemeData(
colorScheme: ColorScheme.dark(primary: primary, /* ... */),
useMaterial3: true,
);
// Explicit Cupertino (for iOS/macOS or forced Cupertino)
static CupertinoThemeData cupertinoLight() => CupertinoThemeData(
brightness: Brightness.light,
primaryColor: primary,
/* ... */
);
static CupertinoThemeData cupertinoDark() => CupertinoThemeData(
brightness: Brightness.dark,
primaryColor: primary,
/* ... */
);
}Layer 2 — BcApp: platform-aware entry point via FPW PlatformApp:
class BcApp extends StatelessWidget {
const BcApp({super.key, this.home, this.routes, this.title});
final Widget? home;
@override
Widget build(BuildContext context) {
return PlatformApp(
// FPW auto-picks: iOS/macOS → Cupertino, else → Material
material: (_, __) => BcTheme.materialLight(),
materialDarkTheme: (_, __) => BcTheme.materialDark(),
cupertino: (_, __) => BcTheme.cupertinoLight(),
home: home,
);
}
}Consumer experience:
// SIMPLE (platform-aware, zero config):
void main() => runApp(BcApp(home: MyScreen()));
// → iOS: Cupertino auto, Ancodebuddy: Material auto, Web: Material auto
// POWERFUL (explicit override):
PlatformApp(
material: (_, __) => BcTheme.materialDark(),
cupertino: (_, __) => BcTheme.cupertinoLight(),
home: MyScreen(),
);
// RAW (token only, no theme):
Container(color: BcTheme.primary.withValues(alpha: 0.5));Rationale:
| Alternatif | Kenapa ditolak |
|---|---|
Single method static ??? adaptive() |
Return type union tidak ada di Dart. Tidak compile. |
Sealed class Either<ThemeData, CupertinoThemeData> |
Consumer tetap if-else (if (theme is ThemeData) ...). Hilang "satu method" benefit. |
| Contract-level Cupertino mapping string | Membengkakkan contract, mengganggu Mitosis, freeze ADR-008 violated. |
SRP terjaga: BcTheme = pure data (testable tanpa widget tree), BcApp = widget (boleh grow dengan locale/router nanti).
Layer 1 — reactive_store.dart (pure Dart, no Flutter import):
// Port of store.ts. Pure Dart. Testable via dart test (no Flutter binding).
class ReactiveStore {
final Map<String, dynamic> _values = {};
final Set<VoidCallback> _listeners = {};
void subscribe(VoidCallback listener) { _listeners.add(listener); }
void unsubscribe(VoidCallback listener) { _listeners.remove(listener); }
dynamic get(String path) { /* ... */ }
void set(String path, dynamic value, BcChangeMeta meta) {
_values[path] = value;
for (final listener in _listeners) {
listener();
}
}
}Layer 2 — reactive_store_notifier.dart (thin Flutter adapter, ~15 lines):
import 'package:flutter/foundation.dart';
class ReactiveStoreNotifier extends ChangeNotifier {
final ReactiveStore _store;
late final VoidCallback _listener;
ReactiveStoreNotifier(this._store) {
_listener = () => notifyListeners();
_store.subscribe(_listener);
}
ReactiveStore get store => _store;
dynamic get(String path) => _store.get(path);
void set(String path, dynamic value, BcChangeMeta meta) =>
_store.set(path, value, meta);
@override
void dispose() {
_store.unsubscribe(_listener);
super.dispose();
}
}Rationale:
| Alternatif | Kenapa ditolak |
|---|---|
(A) ChangeNotifier di core |
Lock core ke Flutter SDK. Violates kontrak "portable". Core tidak reusable di CLI/server/future Dart targets. |
| (B) Pure Dart tanpa adapter | Setiap widget reinvent wiring = drift. 176 widget = 176 tempat rawan lupa cleanup. Memory leak. |
Mirror arsitektur existing TS: store.ts (pure, no DOM) + wc-event-bridge.ts (web adapter). Konsistensi lintas bahasa = maintainable.
The Dart BcRenderer port uses a hybrid approach rather than forcing all schema rendering into either BcForm or a separate renderer stack.
Decision:
BcFormremains the form primitive and is enhanced with optional schema-drivenfields,actions, andlayoutinputs.BcForm(child: ...)legacy mode remains source-compatible and unchanged for existing callers.BcFieldBuilderis standalone and mapsFieldNodeto existing Flutter field widgets.BcDataSourceLoaderis standalone and loads null, local, fetcher, URL, and model data sources.BcRendereris the schema compositor. It dispatchesform,detail,list,section,grid, andcustomkinds, then delegates field and data behavior to the standalone builders/loaders.- Action buttons are platform-aware through Flutter platform widget patterns, while complex data/list rendering stays Flutter-native and testable.
Rationale:
| Alternatif | Kenapa ditolak |
|---|---|
Put all renderer behavior inside BcForm |
BcForm would become a god widget. List, section, grid, custom recursion, and data source loading are not form responsibilities. |
| Separate renderer stack with a new form implementation | Would duplicate store/action/layout behavior and risk drifting from the established BcForm API. |
| Stub unsupported schema kinds | Violates production-grade requirement and breaks parity with metadata-driven UI. |
| Hybrid approach | Preserves BcForm compatibility, keeps field/data concerns reusable, and gives BcRenderer one clear job: schema composition. |
Implementation result (2026-06-24):
BcFieldBuildermaps every currentFieldTypeto existing Flutter widgets and usesReactiveStorepublic APIs.BcDataSourceLoadersupports all current DartDataSourcevariants with deterministic empty/error behavior and offline-safe test seams.BcFormsupports schema fields, actions, layout, disabled state, and callbacks while preserving child-only mode.BcRenderersupports all six schema kinds with recursive rendering, custom builder support, list loading/error/empty states, and package-root exports.- Validation passed: 215 renderer assertions, 269 renderer scoped tests, 1427 full Flutter tests,
dart analyze lib/clean, andbuild_runnerin sync.
Widget dengan native Cupertino counterpart (~12 widget) pakai flutter_platform_widgets (Platform.*):
// BcInput adaptive via FPW:
class BcInput extends StatelessWidget {
const BcInput({
super.key,
this.label,
this.value,
this.onValueChange,
});
final String? label;
final String? value;
final void Function(String, BcChangeMeta)? onValueChange;
@override
Widget build(BuildContext context) {
return PlatformTextField(
material: (_, __) => MaterialTextFieldData(
decoration: InputDecoration(labelText: label),
onChanged: (v) => onValueChange?.call(v, BcChangeMeta(reason: BcChangeReason.input, source: BcEventSource.pointer)),
),
cupertino: (_, __) => CupertinoTextFieldData(
placeholder: label,
onChanged: (v) => onValueChange?.call(v, BcChangeMeta(reason: BcChangeReason.input, source: BcEventSource.pointer)),
),
);
}
}Widget tanpa Cupertino counterpart (~10 widget: DataTable, Splitter, Accordion, dll) stay Material-only di semua platform:
// BcDataTable: Material-only, no adaptive:
class BcDataTable extends StatelessWidget {
// ... pure Material 3 DataGrid
}Contract impact: ZERO. .contract.ts tetap Material-canonical dengan satu flutter: mapping string (descriptive, bukan binding codegen). ADR-008 freeze tidak violated. Tidak ada dual mapping string per-platform.
Rationale:
| Alternatif | Kenapa ditolak |
|---|---|
| Hand-roll semua 22 widget | 12 widget yang ada Cupertino equivalent akan terlihat non-native di iOS. |
| FPW untuk semua 22 widget | FPW tidak punya Cupertino counterpart untuk DataTable/Splitter/Accordion. Pakai Material via FPW tetap Material. |
| Contract-level adaptive mapping | Membengkakkan contract, mengganggu Mitosis, ADR-008 freeze violated. |
enum BcEventSource { pointer, keyboard, programmatic, external }
enum BcChangeReason { input, reaction, programmatic, select, toggle, submit }
class BcChangeMeta {
final BcChangeReason reason;
final BcEventSource source;
final Object? nativeEvent;
const BcChangeMeta({
required this.reason,
this.source = BcEventSource.programmatic,
this.nativeEvent,
});
}Rationale:
| Alternatif | Kenapa ditolak |
|---|---|
(A) Generic BcChangeMeta<TReason extends String> |
Dart enum lebih type-safe dari string literal union. Generic menambah complexity di consumer. |
| (B) String-based reason seperti TS | Dart enum = exhaustiveness check di switch. Lebih robust. |
Non-generic karena: (1) consumer tidak perlu annotate BcChangeMeta<'input'>, (2) enum sudah type-safe, (3) mirror TS contract tanpa generic overhead.
- Consumer DX = 100% identik across React/RN/Vue/Flutter. 1 API, 5 target.
- Core portable —
reactive_store.dartreusable di CLI/server/future Dart targets. - Const-first —
static const Color= compile-time, zero allocation, idiomatic Flutter. - Platform-aware by default —
BcApp(home: ...)satu line, auto Cupertino/Material. - Contract untouched — ADR-008 freeze preserved. Flutter mapping string descriptive only.
- Token parity —
Color.withValues(alpha:)= Tailwindhsl(var(--x) / 0.5). - Adaptive where it matters — iOS user gets CupertinoTextField, not Material TextField.
- Generator delivers P1 widgets — Phase 5b generator stubs 80% simple widget dari contract; Phase 5b.2 promoted 8 generated stubs to completed widgets.
- 25% library-dev overhead —
bc_xx.dartwritten separately from.lite.tsx. Tidak ada compiler TSX→Dart yang reliable. - FPW dependency —
flutter_platform_widgetsadded topubspec.yaml. Lock-in ke library eksternal. - Return type duality —
BcThemeexpose 4 factory methods (2 ThemeData + 2 CupertinoThemeData). Consumer yang pakaiCupertinoAppexplicit harus importcupertinoLight(). - No runtime HSL mutation — Hex const tidak bisa di-mutate runtime untuk dynamic theming. Token change = re-run generator. Acceptable: BitCode tidak punya use case runtime hue-shift.
- Hand-write P0 first — 22 widget hand-written sebelum generator (Phase 5a). Effort upfront, tapi validate pattern dengan kode nyata.
Trade-off utama: 25% library-dev overhead vs 100% consumer DX parity. Prinsip project: "DX user prioritized over library developer convenience." Keputusan ini selaras.
FPW lock-in mitigated: FPW thin wrapper over Flutter native widgets. Kalau FPW deprecated, migration path = replace Platform.* dengan native widget + manual Platform.isIOS check. Bukan rewrite.
Phase 5a (current scope):
-
packages/ui-flutter/scaffolded withpubspec.yaml, barrel export, directory structure -
generate-flutter-tokens.mjsparsestheme.css→ emitsbc_theme.dartwith 30+const Color -
bc_theme.darthasBcThemeclass with const colors + 4 factory methods (materialLight/Dark, cupertinoLight/Dark) -
bc_app.darthasBcAppwidget wrappingPlatformAppwith BcTheme defaults -
types.darthasBcEventSourceenum,BcChangeReasonenum,BcChangeMetaclass (non-generic) -
reactive_store.dart(pure Dart) passes unit tests without Flutter binding -
reactive_store_notifier.dart(Flutter adapter) passes widget tests - 22 P0 widgets implemented (12 FPW adaptive + 10 Material-only)
- Consumer API matches
.contract.tsfor all 22 widgets -
flutter testpasses for all widget tests -
dart analyzeclean (zero warnings) - ADR-011 referenced in
docs/adr/README.mdindex
Phase 5b:
- Generator stubs 80% simple widget dari contract —
generate-flutter-stubs.mjsparses 32 contracts with flutter hints, protects 24 P0 hand-written files, and generated the initial 8 P1 stubs in Phase 5b.1 - Generator fixes landed for Phase 5b.2 — extends clause walking and
Promise<T>toFuture<T>mapping - UiSchema types ported to Dart (freezed + json_serializable) —
ui_schema_types.dart,ui_schema_events.dart,ui_schema.dart,field_resolver.dart+ generated.freezed.dart/.g.dartfiles - Core type parity updated —
BcChangeReasonextended to 18 values with typed Dart classes/enums - Phase 5b.2 targeted P1 Flutter batch completed —
BcDisclosure,BcPortal,BcFieldDuration,BcFieldTableSelect,BcFieldMorph,BcFieldDynLink,BcLookupModal,BcViewGantt - Phase 5b.2 integration gate passed — 416 Flutter tests pass,
flutter analyzereturns 0 errors/warnings (info hints only),build_runnersucceeds, and 252/252 validation assertions passed - BcRenderer Dart hybrid port complete —
BcFieldBuilder,BcDataSourceLoader, schema-drivenBcForm, andBcRenderercompositor support form/detail/list/section/grid/custom schemas with 215/215 validation assertions passed - Remaining P1/P2 Flutter parity outside Phase 5b.2 and renderer-port scope
- Scaffold
packages/ui-flutter/—pubspec.yaml+ barrel + directory structure packages/ui/scripts/generate-flutter-tokens.mjs— parsetheme.css→bc_theme.dart- Core types —
types.dart(BcChangeMeta, BcEventSource, BcChangeReason) - Reactive store —
reactive_store.dart(pure Dart) +reactive_store_notifier.dart(Flutter adapter) - Token bridge —
bc_theme.dart(3-layer: colors → explicit → app) bc_app.dart—BcAppwidget (PlatformApp wrapper)- 22 P0 widgets with adaptive FPW + hand-roll
- Tests
- Docs update (codebase.md, components-progress.md)
- Commit
- Contract → Dart stub generator — ✅
generate-flutter-stubs.mjs(Phase 5b.1) - UiSchema types port (freezed + json_serializable) — ✅ 4 source files + 8 generated (Phase 5b.1)
- Generator correctness fixes — ✅ extends clause walking and
Promise<T>toFuture<T>mapping (Phase 5b.2) - P1 targeted Flutter batch — ✅ 8 widgets complete:
BcDisclosure,BcPortal,BcFieldDuration,BcFieldTableSelect,BcFieldMorph,BcFieldDynLink,BcLookupModal,BcViewGantt(Phase 5b.2) - Integration gate — ✅ 416 Flutter tests pass,
flutter analyzereturns 0 errors/warnings (info hints only),build_runnersucceeds, 252/252 validation assertions passed - BcRenderer hybrid Dart port — ✅
BcFieldBuilder,BcDataSourceLoader, schema-drivenBcForm, andBcRenderercompositor complete (2026-06-24) - Remaining P1/P2 Flutter parity — pending outside Phase 5b.2 and renderer-port scope
- P2 (~90 widget) implemented
- Full parity with web side
- ADR-011 acceptance criteria Phase 5c checked
- ADR-002: Cross-Platform Architecture — Defines Tier C (Flutter) as separate track. ADR-011 implements Tier C.
- ADR-007: Enterprise Universal UI API Contract — Defines semantic event/state/method contracts. ADR-011 ports these to Dart.
- ADR-008: Contract-First API Freeze — Freezes contract. ADR-011 adds Flutter mapping string without modifying frozen surfaces.
- ADR-004: Reactive Engine — Defines reactive store semantics. ADR-011 ports to pure Dart.
- ADR-005: Metadata-Driven UI — Defines UiSchema renderer. ADR-011 ports to Dart (Phase 5a scope: types only, renderer Phase 5b).
packages/ui/tokens/theme.css— HSL token source of truthpackages/ui/src/core/store.ts— Reactive store (TS source for port)packages/ui/src/core/types.ts— BcChangeMeta, BcEventSource types (TS source for port)packages/ui/src/core/renderer/BcRenderer.contract.ts— Schema renderer contract- flutter_platform_widgets — FPW library
- Flutter Color.withValues() — Native alpha manipulation
- MaterialBasedCupertinoThemeData — Material → Cupertino theme bridge