Skip to content

Adding widgets through code #53

Closed Answered by DanPeled
DanPeled asked this question in Q&A
Discussion options

You must be logged in to vote

Resolved, here was the fix:

void pasteWidget(WidgetContainerModel? widget, Offset globalPosition) {
   if (widget == null) return;
   Map<String, dynamic> jsonData = widget.toJson();
   jsonData['x'] = getLocalPosition(globalPosition).dx;
   jsonData['y'] = getLocalPosition(globalPosition).dy;

   WidgetContainerModel createdWidget = createWidgetFromJson(jsonData);

   _widgetModels.add(createdWidget);
   refresh();
 }

 WidgetContainerModel createWidgetFromJson(Map<String, dynamic> json) {
   String type = json['type'];
   if (json['type'] == 'List Layout') {
     switch (type) {
       case 'List Layout':
         return ListLayoutModel.fromJson(
             jsonData: json, tabGrid: this

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by DanPeled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant