9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
91 lines
3.1 KiB
Dart
91 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import 'chat_question_card_model.dart';
|
|
|
|
/// Native option controls for one question field. Single-select uses the host's
|
|
/// radio/checklist pattern, multi-select toggles choices, and `onChanged`
|
|
/// receives the protocol value with `false`/`0` preserved.
|
|
Widget chatQuestionOptionsField({
|
|
required BuildContext context,
|
|
required JsonMap field,
|
|
required String keyName,
|
|
required Map<String, dynamic> answers,
|
|
required void Function(String key, Object? value) onChanged,
|
|
}) {
|
|
final options = chatQuestionOptions(field);
|
|
if (options.isEmpty) return const SizedBox.shrink();
|
|
final multi = '${field['type'] ?? ''}' == 'multiselect';
|
|
final value = answers[keyName];
|
|
final selected = multi
|
|
? (value is List ? value.map((entry) => '$entry').toSet() : <String>{})
|
|
: <String>{if (value is String) value};
|
|
if (multi) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (final option in options)
|
|
CheckboxListTile(
|
|
value: selected.contains(chatQuestionOptionValue(option)),
|
|
title: Text(chatQuestionOptionLabel(option)),
|
|
subtitle: '${option['description'] ?? ''}'.trim().isEmpty
|
|
? null
|
|
: Text('${option['description']}'.trim()),
|
|
contentPadding: EdgeInsets.zero,
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
onChanged: (on) => onChanged(
|
|
keyName,
|
|
_toggle(selected, chatQuestionOptionValue(option)),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
return RadioGroup<String>(
|
|
groupValue: value is String ? value : null,
|
|
onChanged: (next) => onChanged(keyName, next),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (final option in options)
|
|
RadioListTile<String>(
|
|
value: chatQuestionOptionValue(option),
|
|
title: Text(chatQuestionOptionLabel(option)),
|
|
subtitle: '${option['description'] ?? ''}'.trim().isEmpty
|
|
? null
|
|
: Text('${option['description']}'.trim()),
|
|
contentPadding: EdgeInsets.zero,
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Yes/No for a boolean field: the web's explicit "Choose Yes or No" menu.
|
|
Widget chatQuestionBooleanField({
|
|
required BuildContext context,
|
|
required JsonMap field,
|
|
required String keyName,
|
|
required Map<String, dynamic> answers,
|
|
required void Function(String key, Object? value) onChanged,
|
|
}) {
|
|
final value = answers[keyName];
|
|
return DropdownButtonFormField<String>(
|
|
initialValue: value is bool ? '$value' : null,
|
|
hint: const Text('Choose Yes or No'),
|
|
items: const [
|
|
DropdownMenuItem(value: 'true', child: Text('Yes')),
|
|
DropdownMenuItem(value: 'false', child: Text('No')),
|
|
],
|
|
onChanged: (next) =>
|
|
onChanged(keyName, chatFormFieldValue(field, next ?? '')),
|
|
);
|
|
}
|
|
|
|
List<String> _toggle(Set<String> selected, String value) {
|
|
final next = {...selected};
|
|
if (!next.add(value)) next.remove(value);
|
|
return next.toList();
|
|
}
|