adding packages
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
{{#imports}}
|
||||
{{path}}
|
||||
{{/imports}}
|
||||
{{#classes}}
|
||||
|
||||
class {{class}}Render<T> extends StatelessWidget {
|
||||
|
||||
factory {{class}}Render.fromJson(Map<String, dynamic> data, VoidCallback update) {
|
||||
return {{class}}Render(update,
|
||||
{{#fields}}
|
||||
{{name}}Val: BaseCore<{{type}}>(null, update),
|
||||
{{/fields}}
|
||||
);
|
||||
}
|
||||
|
||||
{{class}}Render(this._update, {
|
||||
{{#fields}}
|
||||
@required this.{{name}}Val,
|
||||
{{/fields}}
|
||||
});
|
||||
|
||||
@override
|
||||
final VoidCallback _update;
|
||||
|
||||
{{#fields}}
|
||||
{{core}} {{name}}Val;
|
||||
|
||||
{{type}} get {{name}} {
|
||||
return {{name}}Val.value;
|
||||
}
|
||||
|
||||
set {{name}}({{type}} val) {
|
||||
if (val == this.{{name}}) {
|
||||
return;
|
||||
}
|
||||
{{name}}Val.value = val;
|
||||
}
|
||||
|
||||
{{/fields}}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> get staticFields => {
|
||||
{{#static}}
|
||||
'{{name}}': {{value}},
|
||||
{{/static}}
|
||||
};
|
||||
|
||||
@override
|
||||
List<Core> get props => [
|
||||
{{#fields}}
|
||||
this.{{name}}Val,
|
||||
{{/fields}}
|
||||
];
|
||||
|
||||
@override
|
||||
String get description {
|
||||
final sb = StringBuffer();
|
||||
{{#comments}}
|
||||
sb.writeln("{{comments}}");
|
||||
{{/comments}}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, Object> get constructors {
|
||||
return {
|
||||
{{#constructors}}
|
||||
'{{name}}': {{className}}(
|
||||
{{#props}}
|
||||
{{key}}{{separator}} this.{{name}},
|
||||
{{/props}}
|
||||
),
|
||||
{{/constructors}}
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, Map<String, dynamic>> get properties {
|
||||
return {
|
||||
{{#constructors}}
|
||||
'{{name}}': {
|
||||
{{#props}}
|
||||
'{{key}}': this.{{name}},
|
||||
{{/props}}
|
||||
},
|
||||
{{/constructors}}
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': '{{class}}',
|
||||
'props': {
|
||||
{{#fields}}
|
||||
'{{name}}': this.{{name}}Val.toJson(),
|
||||
{{/fields}}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> toCode() {
|
||||
return {
|
||||
{{#constructors}}
|
||||
'{{name}}': """{{className}}(
|
||||
{{#props}}
|
||||
{{key}}{{separator}} ${this.{{name}}Val.toCode()},
|
||||
{{/props}}
|
||||
)""",
|
||||
{{/constructors}}
|
||||
};
|
||||
}
|
||||
|
||||
final _controller = ValueNotifier<WidgetRect>(null);
|
||||
ValueListenable<WidgetRect> get stats => _controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (isWidget) return TrackedWidget(
|
||||
controller: _controller,
|
||||
child: defaultBase,
|
||||
);
|
||||
return Container();
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isWidget => defaultBase is Widget;
|
||||
|
||||
@override
|
||||
Object get defaultBase => constructors['default'];
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
{{#fields}}
|
||||
properties.add(DiagnosticsProperty('{{name}}', this.{{name}}));
|
||||
{{/fields}}
|
||||
}
|
||||
}
|
||||
|
||||
{{/classes}}
|
||||
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
@mustCallSuper
|
||||
class TrackedWidget extends SingleChildRenderObjectWidget {
|
||||
TrackedWidget({
|
||||
Key key,
|
||||
@required Widget child,
|
||||
@required this.controller,
|
||||
}) : super(key: key, child: child);
|
||||
|
||||
final ValueNotifier<WidgetRect> controller;
|
||||
|
||||
@override
|
||||
RenderObject createRenderObject(BuildContext context) {
|
||||
return WidgetBaseRenderObject(controller);
|
||||
}
|
||||
}
|
||||
|
||||
@immutable
|
||||
class WidgetRect {
|
||||
final double lastDx;
|
||||
final double lastDy;
|
||||
final double lastDw;
|
||||
final double lastDh;
|
||||
|
||||
WidgetRect({
|
||||
this.lastDx = 0.0,
|
||||
this.lastDy = 0.0,
|
||||
this.lastDw = 0.0,
|
||||
this.lastDh = 0.0,
|
||||
});
|
||||
|
||||
WidgetRect copyWith({
|
||||
double lastDx,
|
||||
double lastDy,
|
||||
double lastDw,
|
||||
double lastDh,
|
||||
}) {
|
||||
return WidgetRect(
|
||||
lastDx: lastDx ?? this.lastDx,
|
||||
lastDy: lastDy ?? this.lastDy,
|
||||
lastDw: lastDw ?? this.lastDw,
|
||||
lastDh: lastDh ?? this.lastDh,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WidgetBaseRenderObject extends RenderProxyBox {
|
||||
WidgetBaseRenderObject(this.controller);
|
||||
|
||||
final ValueNotifier<WidgetRect> controller;
|
||||
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
assert(!debugNeedsLayout);
|
||||
final current = controller.value;
|
||||
controller.value = current.copyWith(lastDx: offset.dx);
|
||||
controller.value = current.copyWith(lastDy: offset.dy);
|
||||
controller.value = current.copyWith(lastDw: size.width);
|
||||
controller.value = current.copyWith(lastDh: size.height);
|
||||
super.paint(context, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
abstract class Core<T> {
|
||||
dynamic get data;
|
||||
ValueChanged<dynamic> get changed;
|
||||
T get fallback;
|
||||
|
||||
T get value;
|
||||
set value(T val);
|
||||
|
||||
String get name => data == null ? null : data['name'];
|
||||
String get type => data == null ? null : data['type'];
|
||||
|
||||
dynamic toCode();
|
||||
dynamic toJson();
|
||||
}
|
||||
|
||||
class BaseCore<T> extends Core<T> {
|
||||
BaseCore(this.data, this.changed);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> data;
|
||||
|
||||
@override
|
||||
final VoidCallback changed;
|
||||
|
||||
@override
|
||||
T get value {
|
||||
if (data == null || data['value'] == null) {
|
||||
return fallback;
|
||||
}
|
||||
return data['value'];
|
||||
}
|
||||
|
||||
@override
|
||||
set value(T val) {
|
||||
if (val == value) {
|
||||
return;
|
||||
}
|
||||
data = {'type': type, 'value': val};
|
||||
changed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
import 'core.dart';
|
||||
|
||||
class EnumObject<T> extends Core<String> {
|
||||
EnumObject(this.data, this.values, this.changed);
|
||||
|
||||
@override
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
@override
|
||||
final ValueChanged<Map<String, dynamic>> changed;
|
||||
|
||||
final List<T> values;
|
||||
|
||||
T get fallback = {{fallback}};
|
||||
|
||||
@override
|
||||
{{type}} get value {
|
||||
if (data == null || data['value'] == null) {
|
||||
return fallback;
|
||||
}
|
||||
final _value = parseValue<{{type}}>(data['value']);
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
set value({{type}} val) {
|
||||
if (val == value) {
|
||||
return;
|
||||
}
|
||||
final _value = serializeValue<{{type}}>(val);
|
||||
changed({'type': type, 'value': _value});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
import 'core.dart';
|
||||
|
||||
class {{name}}Object extends Core<{{type}}> {
|
||||
{{name}}Object(this.data, this.changed);
|
||||
|
||||
@override
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
@override
|
||||
final ValueChanged<Map<String, dynamic>> changed;
|
||||
|
||||
T get fallback = {{fallback}};
|
||||
|
||||
@override
|
||||
{{type}} get value {
|
||||
if (data == null || data['value'] == null) {
|
||||
return fallback;
|
||||
}
|
||||
final _value = parseValue<{{type}}>(data['value']);
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
set value({{type}} val) {
|
||||
if (val == value) {
|
||||
return;
|
||||
}
|
||||
final _value = serializeValue<{{type}}>(val);
|
||||
changed({'type': type, 'value': _value});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
class {{name}}Object<{{type}}> {
|
||||
{{name}}Object(this._data, this._changed);
|
||||
|
||||
final Map<String, dynamic> _data;
|
||||
final VoidCallback _changed;
|
||||
|
||||
{{type}} get value {
|
||||
if (_data == null) {
|
||||
return null;
|
||||
}
|
||||
return _data['value'];
|
||||
}
|
||||
|
||||
set value({{type}} val) {
|
||||
if (val == value) {
|
||||
return;
|
||||
}
|
||||
_data['value'] = val;
|
||||
_changed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
{{#imports}}
|
||||
{{path}}
|
||||
{{/imports}}
|
||||
|
||||
class {{class}}Base extends BaseWidget {
|
||||
{{class}}Base({
|
||||
@required this.constructor,
|
||||
{{#fields}}
|
||||
{{type}} {{name}},
|
||||
{{/fields}}
|
||||
}) {{constructor_divider}}
|
||||
{{#fields}}
|
||||
this._{{name}} = {{name}},
|
||||
{{/fields}}
|
||||
{
|
||||
this.value = this.toJson();
|
||||
}
|
||||
|
||||
@override
|
||||
final String constructor;
|
||||
|
||||
factory {{class}}Base.fromJson(Map<String, dynamic> data, String constructor) {
|
||||
return {{class}}Base(
|
||||
constructor: constructor,
|
||||
{{#fields}}
|
||||
{{name}}: {{value}},
|
||||
{{/fields}}
|
||||
);
|
||||
}
|
||||
|
||||
factory {{class}}Base.readOnly() {
|
||||
return {{class}}Base(
|
||||
constructor: '{{class}}',
|
||||
{{#fields}}
|
||||
{{name}}: null,
|
||||
{{/fields}}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get description => r"""
|
||||
{{description}}
|
||||
""";
|
||||
|
||||
{{#fields}}
|
||||
{{type}} _{{name}};
|
||||
{{/fields}}
|
||||
|
||||
@override
|
||||
Map<String, String> get properties => {
|
||||
{{#fields}}
|
||||
'{{key}}': '{{type}}',
|
||||
{{/fields}}
|
||||
};
|
||||
|
||||
@override
|
||||
void setProperty(String name, dynamic value) {
|
||||
switch(name) {
|
||||
{{#fields}}
|
||||
case '{{name}}':
|
||||
this._{{name}} = value;
|
||||
break;
|
||||
{{/fields}}
|
||||
default:
|
||||
}
|
||||
this.value = this.toJson();
|
||||
this.notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
dynamic getProperty(String name) {
|
||||
switch(name) {
|
||||
{{#fields}}
|
||||
case '{{name}}':
|
||||
return this._{{name}};
|
||||
{{/fields}}
|
||||
default:
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name' : '${constructor}',
|
||||
'params': {
|
||||
{{#fields}}
|
||||
'{{key}}': this._{{name}},
|
||||
{{/fields}}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, Object> flavors(BuildContext context) {
|
||||
return {
|
||||
{{#constructors}}
|
||||
'{{name}}': {{widget}},
|
||||
{{/constructors}}
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get constructors => [
|
||||
{{#constructors}}
|
||||
'{{name}}',
|
||||
{{/constructors}}
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user