rand dart fix

This commit is contained in:
2026-01-15 17:36:22 -08:00
parent dbbdafd893
commit 91e7e39fe8
131 changed files with 976 additions and 1365 deletions
@@ -74,37 +74,33 @@ class __WidgetAcceptState extends State<_WidgetAccept> {
@override
Widget build(BuildContext context) {
if (widget.child != null) {
return widget.child;
}
if (!widget.scope.isDragging) {
return widget.child;
if (!widget.scope.isDragging) {
return SizedBox.fromSize(
size: widget.sizeOnlyDragging ? null : widget.size,
child: Container(),
);
}
return SizedBox(
height: widget?.size?.height,
width: widget?.size?.width,
height: widget.size.height,
width: widget.size.width,
child: DragTarget<Map<String, dynamic>>(
onAccept: (val) {
onAcceptWithDetails: (val) {
if (mounted) {
setState(() {
_accepting = false;
});
}
if (val != null) {
final _data = val;
_data['id'] = StringGen.id;
if (_data['name'] == 'Text') {
_data['params']['style']['id'] = StringGen.id;
}
if (_data['name'] == 'Icon') {
_data['params']['0']['id'] = StringGen.id;
}
widget.onAccept(context, _data);
final _data = val;
_data['id'] = StringGen.id;
if (_data['name'] == 'Text') {
_data['params']['style']['id'] = StringGen.id;
}
},
if (_data['name'] == 'Icon') {
_data['params']['0']['id'] = StringGen.id;
}
widget.onAccept(context, _data);
},
onLeave: (val) {
if (mounted) {
setState(() {
@@ -112,7 +108,7 @@ class __WidgetAcceptState extends State<_WidgetAccept> {
});
}
},
onWillAccept: (val) {
onWillAcceptWithDetails: (val) {
if (mounted) {
setState(() {
_accepting = true;
@@ -123,11 +119,11 @@ class __WidgetAcceptState extends State<_WidgetAccept> {
builder: (context, accepted, rejected) {
return Center(
child: Container(
width: widget?.size?.width,
height: widget?.size?.height,
width: widget.size.width,
height: widget.size.height,
child: Placeholder(
color:
!_accepting ? Colors.grey : Theme.of(context).accentColor,
!_accepting ? Colors.grey : Theme.of(context).colorScheme.secondary,
),
),
);
@@ -143,13 +139,9 @@ Map<String, dynamic> modifyAccept(Map<String, dynamic> val,
_data['id'] = StringGen.id;
switch (_data['name']) {
case 'Container':
if (height != null) {
_data['params']['height'] = height;
}
if (width != null) {
_data['params']['width'] = width;
}
break;
_data['params']['height'] = height;
_data['params']['width'] = width;
break;
default:
}
return _data;
@@ -25,104 +25,95 @@ class DynamicWidget extends StatelessWidget implements WidgetLibrary {
}
WidgetConfig get base {
if (data != null) {
if (library[data['name']] != null) {
final _base = library[data['name']];
if (_base != null) {
return _base;
}
if (library[data['name']] != null) {
final _base = library[data['name']];
if (_base != null) {
return _base;
}
}
if (unknownWidgetBuilder != null) {
return unknownWidgetBuilder(data);
}
return null;
return null;
}
static void onAction(BuildContext context, String val) {
final data = val;
if (data == null) return null;
if (data is String) {
if (data.isEmpty) return null;
final _data = data.replaceAll('#', '');
if (_data.startsWith('message')) {
final _message = _data
.replaceAll('message(', '')
.replaceAll('(', '')
.replaceAll(')', '');
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(_message),
));
return;
}
if (_data.startsWith('navigate')) {
final _route = _data
.replaceAll('navigate(', '')
.replaceAll('(', '')
.replaceAll(')', '');
Navigator.of(context).pushNamed(_route);
return;
}
if (_data.startsWith('pop')) {
final _route = _data
.replaceAll('pop(', '')
.replaceAll('(', '')
.replaceAll(')', '');
if (_route.isNotEmpty) {
Navigator.popUntil(context, ModalRoute.withName(_route));
} else {
Navigator.of(context).pop();
}
return;
}
if (_data.startsWith('maybePop')) {
Navigator.of(context).maybePop();
return;
}
if (_data.startsWith('launch')) {
final _url = _data
.replaceAll("launch(", '')
.replaceAll('(', '')
.replaceAll(')', '')
.replaceAll("\'", '');
launch('$_url');
return;
}
if (_data.startsWith('alert')) {
final _message = _data
.replaceAll('alert(', '')
.replaceAll('(', '')
.replaceAll(')', '');
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Info'),
content: Text(_message),
actions: [
FlatButton(
child: Text('Ok'),
onPressed: () => Navigator.maybePop(context),
),
],
),
);
return;
}
if (data.isEmpty) return null;
final _data = data.replaceAll('#', '');
if (_data.startsWith('message')) {
final _message = _data
.replaceAll('message(', '')
.replaceAll('(', '')
.replaceAll(')', '');
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(_message),
));
return;
}
return null;
if (_data.startsWith('navigate')) {
final _route = _data
.replaceAll('navigate(', '')
.replaceAll('(', '')
.replaceAll(')', '');
Navigator.of(context).pushNamed(_route);
return;
}
if (_data.startsWith('pop')) {
final _route = _data
.replaceAll('pop(', '')
.replaceAll('(', '')
.replaceAll(')', '');
if (_route.isNotEmpty) {
Navigator.popUntil(context, ModalRoute.withName(_route));
} else {
Navigator.of(context).pop();
}
return;
}
if (_data.startsWith('maybePop')) {
Navigator.of(context).maybePop();
return;
}
if (_data.startsWith('launch')) {
final _url = _data
.replaceAll("launch(", '')
.replaceAll('(', '')
.replaceAll(')', '')
.replaceAll("\'", '');
launch('$_url');
return;
}
if (_data.startsWith('alert')) {
final _message = _data
.replaceAll('alert(', '')
.replaceAll('(', '')
.replaceAll(')', '');
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Info'),
content: Text(_message),
actions: [
FlatButton(
child: Text('Ok'),
onPressed: () => Navigator.maybePop(context),
),
],
),
);
return;
}
return null;
}
Widget render(BuildContext context, [bool nullOk = false]) {
if (base != null) {
if (base is WidgetBase) {
return Builder(
builder: (context) {
return (base as WidgetBase)?.build(context);
},
);
}
if (base is WidgetBase) {
return Builder(
builder: (context) {
return (base as WidgetBase).build(context);
},
);
}
if (nullOk) {
if (nullOk) {
return null;
}
return Container();
@@ -1,6 +1,4 @@
import '../../flutter_dynamic_widget.dart';
import '../base.dart';
import './index.dart';
class MaterialBase extends WidgetLibrary {
MaterialBase(this.data, this.widgetContext);
@@ -10,7 +8,7 @@ class MaterialBase extends WidgetLibrary {
GenerateWidget get widgetRender => (context, data) {
if (data is Map) {
final _base = MaterialBase(data, context);
final _config = _base?.base;
final _config = _base.base;
if (_config is WidgetBase) {
return _config;
}
@@ -40,14 +38,13 @@ class MaterialBase extends WidgetLibrary {
@override
WidgetConfig get base {
if (data == null) return null;
final name = data['name'].toString();
final _materialBase = library[name];
if (_materialBase != null) return _materialBase;
return DynamicWidget(
data: data,
widgetContext: widgetContext,
)?.base;
).base;
}
static ActionCallback onAction = (context, val) {
@@ -3,7 +3,6 @@ import 'package:url_launcher/url_launcher.dart';
import 'string_gen.dart';
T getEnum<T>(String val, {T fallback, List<T> values}) {
if (val == null) return fallback;
final _value = val.replaceAll('#', '');
return values.firstWhere(
(element) => element.toString() == _value,
@@ -21,7 +20,6 @@ Key getKey(dynamic value, [Key fallback]) {
}
Paint getPaint(Map<String, dynamic> data, [Paint fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
// TODO: get values here
@@ -29,7 +27,6 @@ Paint getPaint(Map<String, dynamic> data, [Paint fallback]) {
}
Decoration getDecoration(Map<String, dynamic> data, [Decoration fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
// TODO: get values here
@@ -37,7 +34,6 @@ Decoration getDecoration(Map<String, dynamic> data, [Decoration fallback]) {
}
Duration getDuration(Map<String, dynamic> data, [Duration fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
if (!params.toString().contains('zero')) {
@@ -62,7 +58,6 @@ Duration getDuration(Map<String, dynamic> data, [Duration fallback]) {
BorderRadiusGeometry getBorderRadiusGeometry(Map<String, dynamic> data,
[BorderRadiusGeometry fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
// TODO: get values here
@@ -70,7 +65,6 @@ BorderRadiusGeometry getBorderRadiusGeometry(Map<String, dynamic> data,
}
Matrix4 getMatrix4(Map<String, dynamic> data, [Matrix4 fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
// TODO: get values here
@@ -79,7 +73,6 @@ Matrix4 getMatrix4(Map<String, dynamic> data, [Matrix4 fallback]) {
BorderStyle getBorderStyle(Map<String, dynamic> data,
[BorderStyle fallback = BorderStyle.none]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
// TODO: get values here
@@ -87,7 +80,6 @@ BorderStyle getBorderStyle(Map<String, dynamic> data,
}
FocusNode getFocusNode(Map<String, dynamic> data, [FocusNode fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
final debugLabel = getString(params['debugLabel']);
@@ -104,7 +96,6 @@ FocusNode getFocusNode(Map<String, dynamic> data, [FocusNode fallback]) {
BorderSide getBorderSide(Map<String, dynamic> data,
[BorderSide fallback = BorderSide.none]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
return null;
@@ -133,7 +124,6 @@ List<Alignment> getAlignmentValues() {
}
ShapeBorder getShapeBorder(Map<String, dynamic> data, [ShapeBorder fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
final top = getBorderSide(params['top']);
@@ -167,7 +157,6 @@ ShapeBorder getShapeBorder(Map<String, dynamic> data, [ShapeBorder fallback]) {
}
Offset getOffset(Map<String, dynamic> data, [Offset fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
final dx = getDouble(params['dx']);
@@ -176,7 +165,6 @@ Offset getOffset(Map<String, dynamic> data, [Offset fallback]) {
}
BoxShadow getBoxShadow(Map<String, dynamic> data, [BoxShadow fallback]) {
if (data == null) return fallback;
if (data['params'] == null) return fallback;
final params = data['params'];
final color = getColor(params['color']);
@@ -226,16 +214,14 @@ Map<String, dynamic> setIconData(IconData value) {
'id': StringGen.id,
'params': {
'0': value.codePoint,
if (value?.fontFamily != null) 'fontFamily': value?.fontFamily,
if (value?.fontPackage != null) 'fontPackage': value?.fontPackage,
if (value?.matchTextDirection != null)
'matchTextDirection': value?.matchTextDirection,
if (value.fontFamily != null) 'fontFamily': value.fontFamily,
if (value.fontPackage != null) 'fontPackage': value.fontPackage,
'matchTextDirection': value.matchTextDirection,
},
};
}
IconData getIconData(Map<String, dynamic> data, [IconData fallback]) {
if (data == null) return fallback;
final name = data['name'];
if (name == 'IconData') {
final params = data['params'];
@@ -258,10 +244,10 @@ IconData getIconData(Map<String, dynamic> data, [IconData fallback]) {
getBool(params['matchTextDirection'], matchTextDirection);
}
return IconData(
codePoint ?? fallback?.codePoint,
fontFamily: fontFamily ?? fallback?.fontFamily,
fontPackage: fontPackage ?? fallback?.fontPackage,
matchTextDirection: matchTextDirection ?? fallback?.matchTextDirection,
codePoint ?? fallback.codePoint,
fontFamily: fontFamily ?? fallback.fontFamily,
fontPackage: fontPackage ?? fallback.fontPackage,
matchTextDirection: matchTextDirection ?? fallback.matchTextDirection,
);
}
return fallback;
@@ -455,10 +441,10 @@ Map<String, dynamic> setEdgeInsets(EdgeInsets val) {
'id': StringGen.id,
'name': 'EdgeInsets.only',
'params': {
'top': val?.top ?? 0,
'bottom': val?.bottom ?? 0,
'left': val?.left ?? 0,
'right': val?.right ?? 0,
'top': val.top ?? 0,
'bottom': val.bottom ?? 0,
'left': val.left ?? 0,
'right': val.right ?? 0,
},
};
}
@@ -471,10 +457,10 @@ extension EdgeInsetUtils on EdgeInsets {
double bottom,
]) {
return EdgeInsets.only(
top: top ?? this?.top ?? 0,
left: left ?? this?.left ?? 0,
right: right ?? this?.right ?? 0,
bottom: bottom ?? this?.bottom ?? 0,
top: top ?? this.top ?? 0,
left: left ?? this.left ?? 0,
right: right ?? this.right ?? 0,
bottom: bottom ?? this.bottom ?? 0,
);
}
@@ -3,7 +3,6 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'base_class.dart';
import 'widget_index.dart';
@@ -941,13 +941,11 @@ class WidgetIndex {
Map<String, dynamic> toMap() {
return {
'version': version,
'widgets': widgets?.map((x) => x?.toMap())?.toList(),
'widgets': widgets.map((x) => x.toMap()).toList(),
};
}
static WidgetIndex fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return WidgetIndex(
version: map['version'],
widgets: List<FlutterWidget>.from(
@@ -980,8 +978,6 @@ class FlutterWidget {
}
static FlutterWidget fromMap(Map<String, dynamic> map) {
if (map == null) return null;
return FlutterWidget(
name: map['name'],
description: map['description'],