96de9f5bea
Keep the Material-only conversation implementation while preserving public Cupertino parameters for callers. Narrow affected tests to Material hosts so the dead platform paths are no longer exercised.
93 lines
3.2 KiB
Dart
93 lines
3.2 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 bool cupertino,
|
|
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 bool cupertino,
|
|
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();
|
|
}
|