Skip to content

Commit 9d5c7c4

Browse files
committed
fixes bug related to controller prop
1 parent 87f62c6 commit 9d5c7c4

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ import 'home.xml.dart';
126126
class HomeController extends HomeControllerBase {
127127
128128
//
129-
// here you can add you own logic and called the variables and methods
130-
// from inside the XML file like this <Text text="ctrl.myText" />
129+
// here you can add you own logic and call the variables and methods
130+
// from the XML file. e.g. <Text text="ctrl.myText" />
131131
//
132132
133133
@override

docs/controllers.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Another way is to define it within the controller class:
1515
```dart
1616
final myTextEditingController = new TextEditingController();
1717
```
18+
And you can access it in XML:
19+
```XML
20+
<TextField controller="ctrl.myTextEditingController" />
21+
```
1822

1923
Sometimes you might need to access the instance of the State, for example, For AnimationControler to work properly, the current State (which inherets from `SingleTickerProviderStateMixin` [mixin](./mixin.md)) must be passed as parameter: `AnimationController(vsync: this)`. for this case you can define it as a `<var />` in the XML file as follow:
2024
```XML

src/generators/class-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class ClassCodeGenerator {
129129
...rootWidget.providers.map(a => this.createControllerVar(a))
130130
];
131131
const disposeLines = [
132-
...controllers.filter(a => !a.isPrivate).map(a => a.name),
132+
...controllers.filter(a => !a.isPrivate && !a.skipGenerate).map(a => a.name),
133133
...vars.filter(a => a.type === 'FormGroup').map(a => a.name)
134134
];
135135

src/resolvers/property-resolver.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class PropertyResolver {
139139
value = ValueTransformersProvider.transform(value, propertyName, widget.type);
140140
}
141141

142-
if (this.isUnNamedParamaeter(propertyName, ownerWidget.type)) {
142+
if (this.isUnNamedParameter(propertyName, ownerWidget.type)) {
143143
propertyName = '';
144144
}
145145

@@ -152,25 +152,29 @@ export class PropertyResolver {
152152

153153
if (propertyName === 'controller') {
154154
property.controller = this.createController(propertyValue);
155-
property.value = 'ctrl.' + property.controller.name;
156-
property.name = 'controller';
155+
property.value = (property.controller.name.indexOf('.') > -1 ? '' : 'ctrl.') + property.controller.name;
156+
// property.name = 'controller';
157157
}
158158

159159
return { property, wrapperWidget, handled };
160160
}
161161

162162
private createController(propertyValue: string): VariableModel {
163+
let skipGenerate = false;
163164
const eqSegments = propertyValue.split('=');
164-
165-
// e.g. controller="ScrollController myController"
166-
let name = eqSegments[0].split(' ')[1];
167-
let type = eqSegments[0].split(' ')[0];
165+
166+
let name = eqSegments[0].split(' ')[1]; // e.g. get the name from "ScrollController myController"
167+
let type = eqSegments[0].split(' ')[0]; // e.g. get the type from "ScrollController myController"
168168
let value;
169169

170170
// there is a name with out type e.g. controller="myController"
171171
if (!name) {
172172
name = type;
173173
type = '';
174+
// e.g. controller="ctrl.myController"
175+
if (name.indexOf('.') > -1) {
176+
skipGenerate = true;
177+
}
174178
}
175179

176180
// controller="TabController myController = TabController(initialIndex: 0, length: 4, vsync: this)"
@@ -191,10 +195,15 @@ export class PropertyResolver {
191195
value = value.trim();
192196
}
193197

194-
return { type, name, value, skipGenerate: !type && !value };
198+
return { type, name, value, skipGenerate: !type && !value || skipGenerate };
195199
}
196200

197-
isUnNamedParamaeter(name: string, widgetType: string): boolean {
201+
isUnNamedParameter(name: string, widgetType: string): boolean {
202+
let result = this.getUnNamedParameter(widgetType) === name;
203+
return result;
204+
}
205+
206+
getUnNamedParameter(widgetType: string): string {
198207
widgetType = widgetType.split('.')[0];
199208

200209
let unnamed: any = {
@@ -207,7 +216,6 @@ export class PropertyResolver {
207216
unnamed = Object.assign(unnamed, this.config.unnamedProperties);
208217
}
209218

210-
let result = unnamed[widgetType] === name;
211-
return result;
219+
return unnamed[widgetType];
212220
}
213221
}

src/resolvers/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { WidgetModel, PropertyModel } from "../models/models";
22

33

44
export function removeDuplicatedBuilders(widget: WidgetModel, parent: WidgetModel | WidgetModel[] | null, parentType: 'wrappedWidgets' | 'widget' | 'widgetList', buildersCache: any) {
5+
if (!widget) {
6+
return;
7+
}
8+
59
// find and remove duplicated StreamBuilder & FutureBuilder that have same value.
610
let detach = false;
711

0 commit comments

Comments
 (0)