Skip to content

Commit

Permalink
fix checkbox answer match. close #57
Browse files Browse the repository at this point in the history
  • Loading branch information
goxiaoy committed May 6, 2023
1 parent fbcf1ef commit f585459
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 72 deletions.
4 changes: 2 additions & 2 deletions example/lib/components/custom_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_survey_js/survey.dart' as s;
import 'package:flutter_survey_js/ui/elements/survey_element_factory.dart';
import 'package:flutter_survey_js/ui/survey_widget.dart';
import 'package:json_editor/json_editor.dart';
import 'package:logging/logging.dart';

class CustomLayoutPage extends StatelessWidget {
Expand Down Expand Up @@ -44,8 +45,7 @@ class CustomLayoutPage extends StatelessWidget {
children: [
Expanded(
child: Container(
child: SingleChildScrollView(
child: Text(v.toString())))),
child: JsonEditor.object(object: v))),
ElevatedButton(
child: const Text('Close'),
onPressed: () => Navigator.pop(context),
Expand Down
53 changes: 0 additions & 53 deletions example/lib/components/from_page.dart

This file was deleted.

4 changes: 2 additions & 2 deletions example/lib/components/simple.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_survey_js/survey.dart' as s;
import 'package:json_editor/json_editor.dart';

class Simple extends StatelessWidget {
final s.Survey? survey;
Expand Down Expand Up @@ -37,8 +38,7 @@ class Simple extends StatelessWidget {
children: [
Expanded(
child: Container(
child: SingleChildScrollView(
child: Text(v.toString())))),
child: JsonEditor.object(object: v))),
ElevatedButton(
child: const Text('Close'),
onPressed: () => Navigator.pop(context),
Expand Down
10 changes: 6 additions & 4 deletions lib/ui/elements/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ class CheckBoxElement extends StatelessWidget {
formArrayName: formControlName,
builder: (context, formArray, child) {
final list = <Widget>[];
for (var element
for (s.Itemvalue element
in (element.choices?.map((p0) => p0.castToItemvalue()).toList() ??
[])) {
list.add(CheckboxListTile(
value: formArray.controls.any((c) => c.value == element.value),
value: formArray.controls
.any((c) => c.value == element.value?.value),
title: Text(element.text ?? element.value?.toString() ?? ''),
onChanged: (v) {
if (v == true) {
formArray.add(FormControl<Object>(value: element.value));
formArray
.add(FormControl<Object>(value: element.value?.value));
} else {
final rs = formArray.controls
.where((c) => c.value == element.value)
.where((c) => c.value == element.value?.value)
.toList();
if (rs.isNotEmpty) {
for (var r in rs) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/elements/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ class _NonReactiveDropdownField extends StatelessWidget {
autofocus: false,
alignment: AlignmentDirectional.centerStart,
onChanged: (value) {
final FormControl<String> formControlValue =
final FormControl<Object> formControlValue =
((ReactiveForm.of(context, listen: false)
as FormControlCollection)
.control(formControlName) as FormControl<String>)
.control(formControlName) as FormControl<Object>)
..updateValue(value);
onChanged?.call(formControlValue);
},
Expand Down
11 changes: 5 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,9 @@ packages:
flutter_survey_js_model:
dependency: "direct main"
description:
name: flutter_survey_js_model
sha256: "773eca6d60b1250615d2a264d9abd800c1769c509f0b83abb0cb6e9a1680ae30"
url: "https://pub.dev"
source: hosted
path: "schema/flutter_survey_js_model"
relative: true
source: path
version: "0.0.2-dev.1"
flutter_svg:
dependency: transitive
Expand Down Expand Up @@ -481,10 +480,10 @@ packages:
dependency: "direct main"
description:
name: intl
sha256: "910f85bce16fb5c6f614e117efa303e85a1731bb0081edf3604a2ae6e9a3cc91"
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted
version: "0.17.0"
version: "0.18.1"
io:
dependency: transitive
description:
Expand Down
5 changes: 2 additions & 3 deletions test/questions/dropdown_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_survey_js/generated/l10n.dart';
import 'package:flutter_survey_js/survey.dart';
import 'package:flutter_survey_js/ui/survey_widget.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:reactive_forms/reactive_forms.dart';

Expand Down Expand Up @@ -378,7 +377,7 @@ void main() {
home: Material(
child: SurveyWidget(
controller: controller,
survey: Survey.fromJson(const {
survey: surveyFromJson(const {
"questions": [
{
"type": "dropdown",
Expand All @@ -394,7 +393,7 @@ void main() {
"otherText": otherText,
}
]
})),
})!),
),
),
);
Expand Down

0 comments on commit f585459

Please sign in to comment.