Skip to content

feat: add Stepper control - #25

Merged
AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/stepper
Nov 2, 2026
Merged

AdamMusa merged 2 commits into
codex/engine-initializationfrom
feat/stepper

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Adds the Stepper control and its Step child type (Work Package F, item F1).

Ruby counterpart: AdamMusa/ruflet#41

Rendering

It follows the three-file adaptive pattern, plus one design-neutral model file:

  • adaptive_stepper.dart dispatches through PlatformControlRenderer. It wraps the result in LayoutControl and renders an ErrorControl for invalid data:
    • no visible steps;
    • a child that is not a Step (the message points to stepper_step);
    • type: horizontal without a bounded height. Both designs give the content an Expanded body, so this case says "Stepper(type: horizontal) needs a bounded height", with the hint "Set height or expand".
  • stepper_steps.dart is design-neutral (it imports widgets.dart only). It holds:
    • step resolution: steps, then block children in controls; hidden steps are skipped;
    • a neutral StepperStepState enum, which the Cupertino side needs because StepState is Material-only;
    • current_step clamping;
    • the event callbacks.
  • Material (material_stepper.dart) uses Flutter's Stepper/Step.
    • controlsBuilder renders FilledButton(continue_text) and TextButton(cancel_text). The labels default to MaterialLocalizations, and each button is disabled when its Ruby handler is absent.
    • show_controls: false gives SizedBox.shrink().
    • ClampingScrollPhysics is set.
    • The widget is keyed by the step ids, so a step list that grows or shrinks gets a fresh State. Flutter asserts the step count never changes.
  • Cupertino (cupertino_stepper.dart) is hand-built from Cupertino and widgets-layer widgets only, with no Material, per D-7.
    • Vertical: each header is a 24 px circle, followed by the title (w600 when current) and an optional subtitle in secondaryLabel.
      • The circle is the theme primaryColor when active or complete, systemGrey3 otherwise, and systemRed on error.
      • It shows the 1-based number, CupertinoIcons.checkmark (complete), pencil (editing) or exclamationmark (error).
      • A 1 px CupertinoColors.separator connector runs at x = 12.
      • The current step's content appears under its header through AnimatedSize, followed by CupertinoButton.filled(continue_text) and CupertinoButton(cancel_text). Cancel uses CupertinoLocalizations and Continue defaults to "Continue".
    • Horizontal: equal-width step columns joined by Expanded hairlines, with titles centred and ellipsised under the circles, then the current content in an Expanded ListView.
      • Deviation from the spec sketch: titles go under the circles, not beside them. Beside them, a header with four or more steps overflowed at phone width, and Flutter's Material horizontal stepper still does.
    • Every step's content stays mounted (offstage when not current), so form state survives moving between steps. This matches Material, whose AnimatedCrossFade keeps hidden bodies mounted.
    • Header taps go through a GestureDetector. They are skipped when there is no handler, when the step is disabled, or when the control is disabled.

Second commit (refactor: name the Step child control explicitly in the stepper model). StepperStep now reads the Step's keys through a field called stepControl instead of control. The updated wire-key audit treats any control.get* read as a read of the registered Stepper, so it reported title, subtitle, content, state, is_active and label as Stepper keys that Ruby lacks. Behaviour is unchanged.

The Ruby PR also stops registering a bare step key (D-6), so the Step child is reachable only as stepper_step/stepperstep. The wire type is still Step, so this renderer needs no change for that.

Wire keys and events

Stepper: steps (falls back to controls), current_step, type (vertical/horizontal), show_controls, continue_text, cancel_text, elevation (Material horizontal header only), connector_color (colour or state map, resolved with selected when active and disabled otherwise, also colours the circles as in Flutter), connector_thickness, clip_behavior, plus the common layout keywords.

Step: title (String or Control), subtitle, content, state (indexed|editing|complete|disabled|error, camelCase or snake_case), is_active, label (horizontal only).

Ruby handler Dart event payload
on_step_tap step_tap tapped step index (int)
on_step_continue step_continue current_step (int); button disabled without handler
on_step_cancel step_cancel current_step (int); button disabled without handler

The stepper is controlled. Dart never changes current_step; Ruby does, with page.update(wizard, current_step: n). Step is a child type only (R3), so it has no createWidget case.

Tests

  • New test/widgets/ruby_stepper_test.dart, 31 tests on iOS (Cupertino) and Android (Material). They check:
    • only the current step's content is hit-testable, and its geometry is below its header and indented;
    • current_step updates from Ruby;
    • tapping step 2 fires step_tap 1, and the tap alone does not move the stepper;
    • taps are ignored without a handler and on disabled steps;
    • continue and cancel fire step_continue and step_cancel with the current step, and their buttons sit below the content;
    • a button without its handler is disabled, and the default labels appear;
    • show_controls: false hides the buttons;
    • each state shows its glyph (complete, editing and error), the Cupertino circle is 24x24, and Material gets the mapped StepState;
    • subtitles render;
    • horizontal in an unbounded parent gives an ErrorControl;
    • bounded horizontal puts content below the header row, with taps and continue working;
    • horizontal labels render;
    • the iOS header fits six long titles;
    • connector colour and thickness, elevation and clip_behavior are passed through;
    • current_step clamps, and the step list can grow;
    • controls works as a fallback;
    • empty or non-Step children give an ErrorControl;
    • Cupertino renders no Material widgets.
  • New matrix fixture Stepper, covered on all 5 platforms.
  • verify_pr.sh with Flutter 3.41.2, re-run after both commits with the Ruby pair on RUBY_PKGS="ruflet_core ruflet_rails": +731: All tests passed! (baseline 695). flutter analyze lib test reports No issues found!. The wire-key audit shows 0 new findings under the key-based comparison: Stepper and Step have every key read and every event fired.
  • Parity note from the audit: elevation is Material-only. It only affects Flutter's horizontal Material header.

Render Ruby stepper with Flutter's Stepper on Material and a hand-built Cupertino stepper (24 px numbered circles, hairline connectors, CupertinoButton continue/cancel) on Apple platforms. The stepper is controlled by Ruby: step_tap, step_continue and step_cancel carry indexes and Dart never moves current_step itself.
StepperStep read the Step's keys through a field called `control`, which the wire-key audit attributes to the Stepper itself. Rename it to stepControl; no behavior change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant