Skip to content

Commit 12db51a

Browse files
fix: align data map truthiness, add condition warning, and bump to 0.10.5
- Treat non-empty data model maps as truthy in isTruthy, matching lists and strings. - Add warning logs when function calls miss the 'call' property or condition expressions are invalid maps. - Bump genui to 0.10.5 and add CHANGELOG.md entry to satisfy CI changelog check.
1 parent d4bc88d commit 12db51a

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎packages/genui/CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# [genui](https://pub.dev/packages/genui) Changelog
22

3+
## 0.10.5
4+
5+
- **Fix**: Resolve validation checks and preserve error messages across basic catalog components.
6+
- Recursively evaluate `List` arguments in `DataContext._evaluateStream` so logical functions (`and`, `or`) receive resolved values.
7+
- Remove invalid `'functionCall'` envelope from `checksToExpression` and support tolerant unwrapping in `_evaluateStream`.
8+
- Align truthiness evaluation in `isTruthy` across primitives, data model objects, and structured `ValidationResult` objects, while warning on malformed expressions or missing functions.
9+
- Migrate `CheckBox`, `Slider`, and `ChoicePicker` to `ValidationHelper.validateStream` to evaluate rules individually and display authored error messages.
10+
311
## 0.10.4
412

513
- **Fix**: `Image` now takes the catalog's `description` property and announces it. The property is what the basic

‎packages/genui/lib/src/model/data_model.dart‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class DataContext implements cf.ExecutionContext {
133133
Stream<Object?> _evaluateFunctionCall(JsonMap callDefinition) {
134134
final name = callDefinition['call'] as String?;
135135
if (name == null) {
136+
genUiLogger.warning(
137+
'Function call missing "call" property: $callDefinition',
138+
);
136139
return Stream.value(null);
137140
}
138141

@@ -177,6 +180,14 @@ class DataContext implements cf.ExecutionContext {
177180
if (condition == null) return Stream.value(false);
178181
if (condition is bool) return Stream.value(condition);
179182

183+
if (condition is Map &&
184+
!condition.containsKey('path') &&
185+
!condition.containsKey('call') &&
186+
!condition.containsKey('functionCall')) {
187+
genUiLogger.warning('Invalid condition expression: $condition');
188+
return Stream.value(false);
189+
}
190+
180191
final Stream<Object?> resultStream = _evaluateStream(condition);
181192
return resultStream.map(isTruthy);
182193
}
@@ -193,7 +204,7 @@ bool isTruthy(Object? value) {
193204
if (value.containsKey('valid') && value['valid'] is bool) {
194205
return value['valid'] as bool;
195206
}
196-
return false;
207+
return value.isNotEmpty;
197208
}
198209
return false;
199210
}

‎packages/genui/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
name: genui
66
description: Generates and displays generative user interfaces (GenUI) in Flutter using AI.
7-
version: 0.10.4
7+
version: 0.10.5
88
homepage: https://github.com/flutter/genui/tree/main/packages/genui
99
license: BSD-3-Clause
1010
issue_tracker: https://github.com/flutter/genui/issues

‎packages/genui/test/model/data_model_test.dart‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,37 @@ void main() {
412412

413413
dataModel.update(DataPath('/str'), '');
414414
expect(await context.evaluateConditionStream(condition).first, isFalse);
415+
416+
// Map truthiness: non-empty map is true, empty map is false
417+
dataModel.update(DataPath('/user'), {'name': 'Ada'});
418+
final userCondition = {'path': '/user'};
419+
expect(
420+
await context.evaluateConditionStream(userCondition).first,
421+
isTrue,
422+
);
423+
424+
dataModel.update(DataPath('/user'), <String, Object?>{});
425+
expect(
426+
await context.evaluateConditionStream(userCondition).first,
427+
isFalse,
428+
);
429+
430+
// ValidationResult map: valid flag determines truthiness
431+
dataModel.update(DataPath('/valResult'), {'valid': true});
432+
final valResultCondition = {'path': '/valResult'};
433+
expect(
434+
await context.evaluateConditionStream(valResultCondition).first,
435+
isTrue,
436+
);
437+
438+
dataModel.update(DataPath('/valResult'), {
439+
'valid': false,
440+
'message': 'err',
441+
});
442+
expect(
443+
await context.evaluateConditionStream(valResultCondition).first,
444+
isFalse,
445+
);
415446
});
416447

417448
test('evaluateConditionStream treats unknown functions and invalid maps as '

0 commit comments

Comments
 (0)