json_ui_builder 0.1.4  json_ui_builder: ^0.1.4 copied to clipboard
json_ui_builder: ^0.1.4 copied to clipboard
A server-driven UI library for Flutter that creates dynamic UIs from JSON configurations with support for HTTP, asset, and local data sources.
JSON UI Builder #

A server-driven UI library for Flutter that creates dynamic UIs from JSON configurations. JSON UI Builder supports fetching configurations from local assets, HTTP endpoints, and local files.
#ui #widget #server-driven-ui #dynamic-widgets
Features #
- ๐ Server-driven UI: Create Flutter UIs from JSON configurations
- ๐ฑ Cross-Platform: Works on Android, iOS, Web, Windows, macOS, and Linux
- ๐ Multiple Data Sources: Support for local assets, HTTP endpoints, and local files
- ๐จ Rich Widget Support: Built-in support for common Flutter widgets
- ๐ง Extensible: Easy to extend with custom widgets
- ๐งช Well Tested: Comprehensive test coverage
- ๐ Type Safe: Full type safety with JSON serialization
Supported Widgets #
- Layout: Scaffold, Column, Row, Container, Padding, Center, Expanded, Flexible, SizedBox
- Text: Text with full TextStyle support
- Buttons: ElevatedButton, TextButton, IconButton
- Navigation: AppBar
- Lists: ListView, GridView, PageView
- Cards: Card
- Input: GestureDetector
- Display: Icon, Divider
- Utility: Spacer
- And more...
๐ Complete Documentation - Comprehensive widget reference with examples
๐ Documentation URL: https://github.com/vikneshgopinathan/flexi_ui/blob/main/documentation.md
๐ GitHub Repository: https://github.com/vikneshgopinathan/flexi_ui
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
  json_ui_builder: ^0.1.2
Platform Support #
JsonUI works on all Flutter-supported platforms:
- ๐ฑ Mobile: Android, iOS
- ๐ Web: Chrome, Firefox, Safari, Edge
- ๐ฅ๏ธ Desktop: Windows, macOS, Linux
Quick Start #
Running the Example #
The example app demonstrates JsonUI across all platforms:
# Clone the repository
git clone https://github.com/vikneshgopinathan/flexi_ui.git
cd flexi_ui/example
# Run on different platforms
flutter run -d chrome          # Web (Chrome)
flutter run -d macos           # macOS Desktop
flutter run -d windows         # Windows Desktop
flutter run -d linux           # Linux Desktop
flutter run -d android         # Android Mobile
flutter run -d ios             # iOS Mobile
Example App Features #
The example app includes:
- ๐๏ธ E-commerce Demo: Complete e-commerce app with homepage, promotions, and product details
- ๐ฑ Simple Example: Basic JsonUI usage with asset data source
- ๐ Documentation Links: Direct access to comprehensive documentation
- ๐ Cross-Platform: Works seamlessly on all supported platforms
โ ๏ธ Breaking Change Notice (v0.1.3+)
Starting from version 0.1.3, the widget name has been changed from
SimpleFlexiUItoJsonUIfor consistency. If you're upgrading from an earlier version, please update your code:// OLD (v0.1.2 and below) SimpleFlexiUI(dataSource: dataSource) // NEW (v0.1.3+) JsonUI(dataSource: dataSource)
1. Basic Usage #
import 'package:json_ui_builder/json_ui_builder.dart';
// Load from asset
const dataSource = DataSourceConfig(
  type: DataSourceType.asset,
  assetPath: 'assets/config.json',
);
JsonUI(dataSource: dataSource)
2. HTTP Configuration #
const dataSource = DataSourceConfig(
  type: DataSourceType.http,
  url: 'https://api.example.com/ui-config',
  headers: {'Authorization': 'Bearer token'},
  timeout: Duration(seconds: 30),
);
JsonUI(dataSource: dataSource)
3. Direct Configuration #
final config = JsonUIConfig(
  rootWidget: WidgetConfig(
    type: 'Scaffold',
    child: WidgetConfig(
      type: 'Center',
      child: WidgetConfig(
        type: 'Text',
        params: {'text': 'Hello World!'},
      ),
    ),
  ),
);
JsonUIBuilder(config: config)
JSON Configuration Format #
Basic Structure #
{
  "type": "Scaffold",
  "params": {
    "backgroundColor": "blue"
  },
  "child": {
    "type": "Column",
    "params": {
      "mainAxisAlignment": "center"
    },
    "children": [
      {
        "type": "Text",
        "params": {
          "text": "Hello World",
          "style": {
            "fontSize": 24,
            "color": "white",
            "fontWeight": "w700"
          }
        }
      }
    ]
  }
}
Supported Parameters #
Text Widget
{
  "type": "Text",
  "params": {
    "text": "Your text here",
    "style": {
      "fontSize": 16,
      "fontWeight": "w400",
      "color": "black",
      "fontStyle": "normal"
    }
  }
}
Container Widget
{
  "type": "Container",
  "params": {
    "width": 100,
    "height": 50,
    "color": "red",
    "padding": {
      "left": 10,
      "right": 10,
      "top": 5,
      "bottom": 5
    }
  }
}
Column/Row Widgets
{
  "type": "Column",
  "params": {
    "mainAxisAlignment": "center",
    "crossAxisAlignment": "start"
  },
  "children": [
    {
      "type": "Text",
      "params": {"text": "First child"}
    },
    {
      "type": "Text", 
      "params": {"text": "Second child"}
    }
  ]
}
Advanced Usage #
Custom Loading and Error Widgets #
JsonUI(
  dataSource: dataSource,
  loadingWidget: CircularProgressIndicator(),
  errorWidget: Text('Custom error message'),
  onError: () => print('Configuration failed to load'),
  onSuccess: () => print('Configuration loaded successfully'),
)
Extending with Custom Widgets #
You can extend the widget factory to support custom widgets:
// In your custom widget factory
Widget createCustomWidget(WidgetConfig config) {
  switch (config.type) {
    case 'MyCustomWidget':
      return MyCustomWidget(
        // Parse your custom parameters
      );
    default:
      return WidgetFactory.createWidget(config);
  }
}
Examples #
Check out the example/ directory for complete working examples:
- Asset Example: Loading configuration from local assets
- HTTP Example: Fetching configuration from remote endpoints
- Builder Example: Using JsonUIBuilder with direct configuration
Testing #
Run the tests with:
flutter test
Contributing #
- Fork the repository
- Create your feature branch (git checkout -b feature/amazing-feature)
- Commit your changes (git commit -m 'Add some amazing feature')
- Push to the branch (git push origin feature/amazing-feature)
- Open a Pull Request
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Roadmap #
- โ More widget support (Image, Icon, etc.)
- โ Animation support
- โ Theme integration
- โ State management integration
- โ Custom widget registration API
- โ Performance optimizations