Skip to content

maxAllowedSelections read as double in multiple_choice widget #575

@mwk24

Description

@mwk24

Describe the bug
MultipleChoiceState.maxAllowedSelections casts _json['maxAllowedSelections'] directly to int?, but the JSON map stores numeric values as doubles. When the field is present you get type 'double' is not a subtype of type 'int?' in type cast. Code reference: packages/genui/lib/src/catalog/core_widgets/multiple_choice.dart:44-45.

To Reproduce

  1. Configure a multiple choice widget that sets maxAllowedSelections (e.g. 3) and let it round-trip through the GenUI JSON map.
  2. The JSON is decoded so numeric literals are double (e.g. 3.0).
  3. When the getter runs, the cast to int? throws and the widget fails to render.

Expected behavior
maxAllowedSelections should accept numeric JSON input and convert it to an int. Reading it as num? and calling .toInt() would avoid the crash.

Additional context
The same pattern might exist in other widget configs that assume JSON numbers deserialize as int. Fixing this getter would unblock multiple choice responses that limit the selection count.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2An issue we'd like to fix eventually, but it's not being actively worked on.a: core_catalogfront-line-handledCan wait until the second-line triage. The front-line triage already checked if it's a P0.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions