From 02199134b7c3e10ae665de94fb0ca77c0e751487 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Thu, 12 Nov 2026 17:38:44 -0500 Subject: [PATCH] M10: Flutter code writes no spacing beside a space distribution flutter_line skipped `spacing:` when the main-axis alignment string contained "Space", but the strings are MainAxisAlignment.spaceBetween, spaceAround and spaceEvenly (lower-case s), so it never matched and the gap was written on top of the distribution. It now checks the MainAlign value itself. Co-Authored-By: Claude Opus 5.5 Model-Effort: Opus 5.5 drove and wrote; Fable 5.2 spotted it --- crates/engine/src/dev/codegen.rs | 21 +++++++++++++++++++++ crates/engine/src/dev/codegen/flutter.rs | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/dev/codegen.rs b/crates/engine/src/dev/codegen.rs index 202f7ef0f..8d448a334 100644 --- a/crates/engine/src/dev/codegen.rs +++ b/crates/engine/src/dev/codegen.rs @@ -675,6 +675,27 @@ mod tests { assert!(!dart.lines().any(|l| l.trim_start().starts_with("void main()")), "a name never leaves its comment: {dart}"); } + #[test] + fn flutter_writes_no_spacing_for_the_space_distributions() { + // The space distributions spread the children themselves; a `spacing:` beside them would + // add the gap on top. + let mut s = Session::new(); + let row = id_of(&s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 300, "height": 40})).unwrap()["id"]).unwrap(); + s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 20, "parent": row})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 60, "y": 0, "width": 50, "height": 20, "parent": row})).unwrap(); + s.execute("layout.add", &json!({"ids": [row], "direction": "horizontal"})).unwrap(); + for (align, flutter) in [("spaceBetween", "spaceBetween"), ("spaceAround", "spaceAround"), ("spaceEvenly", "spaceEvenly")] { + s.execute("node.set", &json!({"id": row, "props": {"gap": 10, "mainAlign": align}})).unwrap(); + let dart = code_for(s.doc().unwrap(), row, CodeLang::Flutter); + assert!(dart.contains(&format!("mainAxisAlignment: MainAxisAlignment.{flutter},")), "{dart}"); + assert!(!dart.contains("spacing:"), "{align} spreads the children itself: {dart}"); + } + // A packed line keeps its gap. + s.execute("node.set", &json!({"id": row, "props": {"gap": 10, "mainAlign": "center"}})).unwrap(); + let dart = code_for(s.doc().unwrap(), row, CodeLang::Flutter); + assert!(dart.contains("spacing: 10,"), "{dart}"); + } + #[test] fn flutter_expands_and_stretches_fill_children() { let mut s = Session::new(); diff --git a/crates/engine/src/dev/codegen/flutter.rs b/crates/engine/src/dev/codegen/flutter.rs index 98f280eaf..7a144a147 100644 --- a/crates/engine/src/dev/codegen/flutter.rs +++ b/crates/engine/src/dev/codegen/flutter.rs @@ -335,7 +335,7 @@ fn flutter_line(ctx: &Ctx, l: &AutoLayout, flow: &[Placed], slot: Option<&Param> out.push_str(&format!("{inner}textBaseline: TextBaseline.alphabetic,\n")); } // The gap between the children; the space distributions already spread them. - if l.gap > 0.0 && flutter_main_align(l.main_align).is_none_or(|m| !m.contains("Space")) { + if l.gap > 0.0 && !matches!(l.main_align, MainAlign::SpaceBetween | MainAlign::SpaceAround | MainAlign::SpaceEvenly) { out.push_str(&format!("{inner}spacing: {},\n", num(l.gap))); } out.push_str(&format!("{inner}children: [\n"));