Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplified context data model.
  • Loading branch information
gspencergoog committed Oct 10, 2025
commit 9dddb73af933d372a4b4451d64033f80c0709be0
32 changes: 2 additions & 30 deletions packages/flutter_genui/lib/src/core/widget_utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -79,34 +77,8 @@ JsonMap resolveContext(
final resolved = <String, Object?>{};
for (final contextEntry in contextDefinitions) {
final entry = contextEntry as JsonMap;
final key = entry['name']! as String;
final valueDefinition = entry;

if (valueDefinition.containsKey('path')) {
resolved[key] = dataContext.getValue(valueDefinition['path'] as String);
} else if (valueDefinition.containsKey('literalString')) {
resolved[key] = valueDefinition['literalString'];
} else if (valueDefinition.containsKey('literalNumber')) {
resolved[key] = valueDefinition['literalNumber'];
} else if (valueDefinition.containsKey('literalBoolean')) {
resolved[key] = valueDefinition['literalBoolean'];
} else {
resolved[key] = null;
throw DataBindingException(
'No data source found to bind context key "$key". '
'Value definition supplied was: ${jsonEncode(valueDefinition)}',
);
}
final key = entry['key']! as String;
resolved[key] = dataContext.getValue(entry['path'] as String);
}
return resolved;
}

class DataBindingException implements Exception {
DataBindingException([this.message = '']);

final String message;

@override
String toString() =>
'$DataBindingException: Could not resolve data binding. $message';
}
20 changes: 4 additions & 16 deletions packages/flutter_genui/lib/src/model/a2ui_schemas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,11 @@ class A2uiSchemas {
'context': S.list(
description:
'A list of name-value pairs to be sent with the action. The '
'values can bind to the data model with a path, and should bind '
'to all of the related widget data for this action.',
'values are bind to the data model with a path, and should bind '
'to all of the related data for this action.',
items: S.object(
description:
'A single piece of data to be sent with the action. Must include '
'a name, but must also include either a path or a literal value. '
'Prefer linking to a data model path if available.',
properties: {
'name': S.string(),
'path': S.string(
description: 'A relative or absolute path in the data model.',
),
'literalString': S.string(),
'literalNumber': S.number(),
'literalBoolean': S.boolean(),
},
required: ['name'],
properties: {'key': S.string(), 'path': S.string()},
required: ['key', 'path'],
),
),
},
Expand Down
Loading