dynamic_ui_executor 1.0.0 copy "dynamic_ui_executor: ^1.0.0" to clipboard
dynamic_ui_executor: ^1.0.0 copied to clipboard

A powerful Flutter plugin for creating dynamic user interfaces from JSON or string definitions at runtime. Perfect for server-driven UI, A/B testing, and flexible app interfaces.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:dynamic_ui_executor/dynamic_ui_executor.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Dynamic UI Executor Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const DemoHomePage(),
    );
  }
}

class DemoHomePage extends StatefulWidget {
  const DemoHomePage({super.key});

  @override
  State<DemoHomePage> createState() => _DemoHomePageState();
}

class _DemoHomePageState extends State<DemoHomePage> {
  int _selectedIndex = 0;

  // String UI Examples - Simplified for guaranteed display
  String get stringExample => """
Column(
  children: [
    Card(
      child: Padding(
        padding: EdgeInsets.all(20),
        child: Column(
          children: [
            Icon(Icons.star, size: 48, color: Colors.orange),
            SizedBox(height: 12),
            Text('String UI Demo', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
            SizedBox(height: 8),
            Text('Beautiful UI from String definitions'),
            SizedBox(height: 16),
            ElevatedButton(
              onPressed: () { _handleAction('showMessage'); },
              child: Text('Click Me'),
            ),
          ],
        ),
      ),
    ),
    SizedBox(height: 16),
    Text('βœ… String UI Working!', style: TextStyle(fontSize: 18, color: Colors.green)),
    SizedBox(height: 16),
    Container(
      height: 100,
      color: Colors.blue,
      child: Center(
        child: Text('Blue Container', style: TextStyle(color: Colors.white, fontSize: 16)),
      ),
    ),
  ],
)
""";

  // JSON UI Example - Fixed structure for proper parsing
  Map<String, dynamic> get jsonExample => {
    "type": "Column",
    "children": [
      {
        "type": "Card",
        "children": [
          {
            "type": "Padding",
            "properties": {
              "padding": "EdgeInsets.all(20)"
            },
            "children": [
              {
                "type": "Column",
                "children": [
                  {
                    "type": "Icon",
                    "properties": {
                      "icon": "dashboard",
                      "size": 48,
                      "color": "Colors.purple"
                    }
                  },
                  {
                    "type": "SizedBox",
                    "properties": {
                      "height": 12
                    }
                  },
                  {
                    "type": "Text",
                    "properties": {
                      "text": "JSON UI Demo",
                      "style": {
                        "fontSize": 24,
                        "fontWeight": "FontWeight.bold"
                      }
                    }
                  },
                  {
                    "type": "SizedBox",
                    "properties": {
                      "height": 8
                    }
                  },
                  {
                    "type": "Text",
                    "properties": {
                      "text": "Beautiful UI from JSON definitions"
                    }
                  },
                  {
                    "type": "SizedBox",
                    "properties": {
                      "height": 16
                    }
                  },
                  {
                    "type": "ElevatedButton",
                    "properties": {
                      "action": "showJsonMessage",
                      "child": {
                        "type": "Text",
                        "properties": {
                          "text": "JSON Action"
                        }
                      }
                    }
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "SizedBox",
        "properties": {
          "height": 16
        }
      },
      {
        "type": "Text",
        "properties": {
          "text": "βœ… JSON UI Working!",
          "style": {
            "fontSize": 18,
            "color": "Colors.green"
          }
        }
      },
      {
        "type": "SizedBox",
        "properties": {
          "height": 16
        }
      },
      {
        "type": "Container",
        "properties": {
          "height": 100,
          "color": "Colors.purple"
        },
        "children": [
          {
            "type": "Center",
            "children": [
              {
                "type": "Text",
                "properties": {
                  "text": "Purple Container",
                  "style": {
                    "color": "Colors.white",
                    "fontSize": 16
                  }
                }
              }
            ]
          }
        ]
      }
    ]
  };

  void _handleAction(String action, [Map<String, dynamic>? params]) {
    print('πŸ”₯ DEBUG: Action triggered: $action with params: $params');
    switch (action) {
      case 'showMessage':
        print('πŸ”₯ DEBUG: Showing string UI message');
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('Hello from String UI!')),
        );
        break;
      case 'showJsonMessage':
        print('πŸ”₯ DEBUG: Showing JSON UI message');
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('Hello from JSON UI!')),
        );
        break;
      default:
        print('πŸ”₯ DEBUG: Unknown action: $action');
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('Action: $action')),
        );
    }
  }

  @override
  Widget build(BuildContext context) {
    print('πŸ”₯ DEBUG: Building main widget, selectedIndex: $_selectedIndex');
    print('πŸ”₯ DEBUG: String example length: ${stringExample.length}');
    print('πŸ”₯ DEBUG: JSON example: ${jsonEncode(jsonExample)}');
    
    return Scaffold(
      appBar: AppBar(
        title: const Text('Dynamic UI Executor'),
        backgroundColor: Colors.deepPurple,
      ),
      body: IndexedStack(
        index: _selectedIndex,
        children: [
          // String UI Tab
          SingleChildScrollView(
            padding: EdgeInsets.all(16),
            child: Builder(
              builder: (context) {
                print('πŸ”₯ DEBUG: Building String UI tab');
                try {
                  return DynamicWidgetExecutor(
                    widgetDefinition: stringExample,
                    actionHandler: _handleAction,
                    errorWidget: Container(
                      padding: EdgeInsets.all(16),
                      child: Column(
                        children: [
                          Icon(Icons.warning, color: Colors.orange, size: 48),
                          SizedBox(height: 16),
                          Text('String UI Parse Error', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
                          SizedBox(height: 8),
                          Text('Check console for details'),
                        ],
                      ),
                    ),
                  );
                } catch (e) {
                  print('πŸ”₯ DEBUG: Exception creating String UI: $e');
                  return Container(
                    padding: EdgeInsets.all(16),
                    child: Column(
                      children: [
                        Icon(Icons.error, color: Colors.red, size: 48),
                        SizedBox(height: 16),
                        Text('String UI Exception: $e'),
                      ],
                    ),
                  );
                }
              },
            ),
          ),
          // JSON UI Tab
          SingleChildScrollView(
            padding: EdgeInsets.all(16),
            child: Builder(
              builder: (context) {
                print('πŸ”₯ DEBUG: Building JSON UI tab');
                try {
                  return DynamicWidgetExecutor(
                    widgetDefinition: jsonEncode(jsonExample),
                    isJson: true,
                    actionHandler: _handleAction,
                    errorWidget: Container(
                      padding: EdgeInsets.all(16),
                      child: Column(
                        children: [
                          Icon(Icons.warning, color: Colors.orange, size: 48),
                          SizedBox(height: 16),
                          Text('JSON UI Parse Error', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
                          SizedBox(height: 8),
                          Text('Check console for details'),
                        ],
                      ),
                    ),
                  );
                } catch (e) {
                  print('πŸ”₯ DEBUG: Exception creating JSON UI: $e');
                  return Container(
                    padding: EdgeInsets.all(16),
                    child: Column(
                      children: [
                        Icon(Icons.error, color: Colors.red, size: 48),
                        SizedBox(height: 16),
                        Text('JSON UI Exception: $e'),
                      ],
                    ),
                  );
                }
              },
            ),
          ),
          // Info Tab
          SingleChildScrollView(
            padding: const EdgeInsets.all(16),
            child: Builder(
              builder: (context) {
                print('πŸ”₯ DEBUG: Building Info tab');
                return const Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'Dynamic UI Executor',
                      style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
                    ),
                    SizedBox(height: 16),
                    Text(
                      'Build Flutter UIs dynamically from JSON or String definitions at runtime.',
                      style: TextStyle(fontSize: 16),
                    ),
                    SizedBox(height: 20),
                    Text(
                      'Features:',
                      style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                    ),
                    SizedBox(height: 8),
                    Text('β€’ Runtime UI generation from JSON/String'),
                    Text('β€’ 50+ supported Flutter widgets'),
                    Text('β€’ Action handling for interactions'),
                    Text('β€’ Server-driven UI capabilities'),
                    Text('β€’ Cross-platform support'),
                    SizedBox(height: 20),
                    Text(
                      'Supported Widgets:',
                      style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                    ),
                    SizedBox(height: 8),
                    Text('β€’ Layout: Scaffold, Column, Row, Container, Card'),
                    Text('β€’ Text: Text with styling'),
                    Text('β€’ Buttons: ElevatedButton, TextButton, OutlinedButton'),
                    Text('β€’ Input: TextField, Switch, Checkbox'),
                    Text('β€’ Lists: ListView, GridView'),
                    Text('β€’ Icons: Icon with customization'),
                    Text('β€’ Spacing: SizedBox, Padding'),
                  ],
                );
              },
            ),
          ),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _selectedIndex,
        onTap: (index) {
          print('πŸ”₯ DEBUG: Tab tapped: $index');
          setState(() => _selectedIndex = index);
        },
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.code),
            label: 'String UI',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.data_object),
            label: 'JSON UI',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.info),
            label: 'Info',
          ),
        ],
      ),
    );
  }
}
0
likes
80
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

A powerful Flutter plugin for creating dynamic user interfaces from JSON or string definitions at runtime. Perfect for server-driven UI, A/B testing, and flexible app interfaces.

Repository (GitHub)
View/report issues

Topics

#dynamic-ui #server-driven-ui #json-ui #runtime-ui #flutter-widgets

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on dynamic_ui_executor

Packages that implement dynamic_ui_executor