Skip to content

Commit

Permalink
trying to fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeiffer committed Jan 17, 2025
1 parent 292b44d commit f9e2810
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 40 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Peiffer Innovations, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 15 additions & 16 deletions packages/codegen/lib/src/builder/json_widget_library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class JsonWidgetLibraryBuilder extends GeneratorForAnnotation<JsonWidget> {
'child',
'children',
};
static const kInternalNames = <String>{
// 'childBuilder',
// 'data',
// 'model',
};

@override
String generateForAnnotatedElement(
Expand Down Expand Up @@ -211,7 +206,7 @@ class JsonWidgetLibraryBuilder extends GeneratorForAnnotation<JsonWidget> {
}
}

widgetName ??= widget.getDisplayString(withNullability: false);
widgetName ??= _withoutNullability(widget.getDisplayString());
widgetName = widgetName.replaceAll(RegExp(r'\<.*\>'), '');
jsonWidgetName ??=
'Json${widgetName.startsWith('_') ? widgetName.substring(1) : widgetName}';
Expand All @@ -225,7 +220,7 @@ class JsonWidgetLibraryBuilder extends GeneratorForAnnotation<JsonWidget> {

if (wCon == null) {
throw Exception(
'Cannot find unnamed constructor in [${widget.getDisplayString(withNullability: false)}]',
'Cannot find unnamed constructor in [${_withoutNullability(widget.getDisplayString())}]',
);
}

Expand Down Expand Up @@ -389,7 +384,7 @@ return model;
c.methods.add(Method((m) {
m.name = method!.name;
m.annotations.add(const CodeExpression(Code('override')));
m.returns = Reference(widget.getDisplayString(withNullability: true));
m.returns = Reference(widget.getDisplayString());

m.optionalParameters.add(Parameter((p) {
p.name = 'childBuilder';
Expand Down Expand Up @@ -453,7 +448,7 @@ final model = createModel(
);
${buf.toString()}
return ${widget.getDisplayString(withNullability: false)}(
return ${_withoutNullability(widget.getDisplayString())}(
${lines.join(',')}${lines.isNotEmpty ? ',' : ''}
);
''');
Expand Down Expand Up @@ -571,7 +566,7 @@ super(
final docs = wConstructor.documentationComment;
if (docs != null) {
c.docs.add(
' /* AUTOGENERATED FROM [${widget.getDisplayString(withNullability: false)}]*/');
' /* AUTOGENERATED FROM [${_withoutNullability(widget.getDisplayString())}]*/');
c.docs.add(docs);
}
c.name = '${name.substring(1)}Model';
Expand Down Expand Up @@ -761,7 +756,7 @@ return result;
}
if (encoder != null) {
customEncoders.write('''
final ${name}Encoded = ${encoder.enclosingElement.name}.${encoder.name}(${param.name});
final ${name}Encoded = ${encoder.enclosingElement3.name}.${encoder.name}(${param.name});
''');

buf.write('''
Expand Down Expand Up @@ -814,7 +809,7 @@ ${buf.toString()}
}
final name = aliases[param.displayName] ?? param.displayName;
if (param.displayName != 'key') {
final type = param.type.getDisplayString(withNullability: false);
final type = _withoutNullability(param.type.getDisplayString());

final sMethod = schemaDecoders[name];
if (sMethod == null) {
Expand All @@ -825,7 +820,7 @@ ${buf.toString()}
} else {
if (!sMethod.isStatic) throw 'Schema only supports static methods';
properties.write(
"'$name': ${sMethod.enclosingElement.name}.${sMethod.displayName}(),",
"'$name': ${sMethod.enclosingElement3.name}.${sMethod.displayName}(),",
);
}
}
Expand Down Expand Up @@ -910,7 +905,7 @@ void _buildClassFields({
}
if (/*!kChildNames.containsKey(p.name) &&*/ p.name != 'key') {
final method = paramDecoders[aliases[p.name] ?? p.name];
var type = p.type.getDisplayString(withNullability: true);
var type = p.type.getDisplayString();

if (type == 'Widget' || type == 'PreferredSizeWidget') {
type = 'JsonWidgetData';
Expand All @@ -930,7 +925,7 @@ void _buildClassFields({
final docs = widgetFieldDocs[p.name];
if (docs != null) {
f.docs.add(
' /* AUTOGENERATED FROM [${widget.getDisplayString(withNullability: false)}.${p.name}]*/',
' /* AUTOGENERATED FROM [${_withoutNullability(widget.getDisplayString())}.${p.name}]*/',
);
f.docs.add(docs);
}
Expand Down Expand Up @@ -1035,7 +1030,7 @@ void _buildCustomParamBuilder({
if (annotation != null || param.name == 'key' || param.name == 'context') {
lines.add('$prefix${param.name}');
} else if (method == null) {
final type = param.type.getDisplayString(withNullability: true);
final type = param.type.getDisplayString();
if (type == 'Widget') {
lines.add('''
${prefix}model.$name.build(
Expand Down Expand Up @@ -1135,3 +1130,7 @@ final ${name}Decoded = ${paramDecoders[aliases[name] ?? name]!.name}(
''');
}
}

String _withoutNullability(String nullableType) => nullableType.endsWith('?')
? nullableType.substring(0, nullableType.length - 1)
: nullableType;
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"type": "set_widget",
"args": {
"widgets": {
"variableWidgetList": {
"type": "text",
"args": {
"text": "This is a text."
"variableWidgetList": [
{
"type": "text",
"args": {
"text": "This is a text."
}
}
}
]
},
"child": {
"type": "scaffold",
Expand All @@ -29,7 +31,7 @@
"variableWidgetList"
],
"args": {
"child": "${variableWidgetList}"
"children": "${variableWidgetList}"
}
}
}
Expand Down
29 changes: 12 additions & 17 deletions packages/json_dynamic_widget/example/assets/pages/issue_289.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@
]
},
"child": {
"type": "expanded",
"type": "dropdown_button_form_field",
"listen": [
"index"
],
"args": {
"child": {
"type": "dropdown_button_form_field",
"listen": [
"index"
],
"args": {
"decoration": {
"labelText": "Select Island"
},
"items": "${index}",
"validators": [
{
"type": "required"
}
]
"decoration": {
"labelText": "Select Island"
},
"items": "${index}",
"validators": [
{
"type": "required"
}
}
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class Issue219Page extends StatelessWidget {
builder: JsonExampleWidgetBuilder.fromDynamic,
));

return const SizedBox();
return Scaffold(
appBar: AppBar(
title: Text('Issue 219'),
),
body: const SizedBox());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
}

0 comments on commit f9e2810

Please sign in to comment.