Custom Widgets
Custom widgets allow you to extend Digia UI with native Flutter components. This is essential for accessing native platform features, integrating third-party packages, and creating specialized UI components that Digia Studio doesn't provide.
Overview
Custom widgets bridge the gap between Digia's visual development environment and Flutter's native capabilities. They allow you to:
Access native platform APIs (camera, GPS, sensors)
Integrate third-party Flutter packages
Create performance-critical custom rendering
Implement complex animations and interactions
Handle platform-specific behaviors
When to Use Custom Widgets
Use Custom Widgets When You Need:
✅ Native Platform Features: Camera, GPS, device sensors, file system access
✅ Third-party Flutter Packages: Complex animations, charts, maps, payment SDKs
✅ Performance-Critical Logic: Custom rendering or complex state management
✅ Missing Digia UI Components: Specialized widgets not available in Digia Studio
✅ Custom Styling: Specific design requirements that Digia UI can't achieve
✅ Platform-Specific Behavior: Different behavior on iOS vs Android
Use Digia UI Directly For:
❌ Basic UI Elements: Buttons, text, images, lists (already available in Digia)
❌ Standard Layouts: Containers, columns, rows, cards
❌ Simple Forms: Text inputs, checkboxes, dropdowns
❌ Navigation: Standard app bars, bottom tabs, drawers
Decision Matrix
Product Card
✅
❌
Standard layout, available in Digia
Shopping Cart
✅
❌
List + standard components
Camera Button
❌
✅
Native camera API needed
Payment Form
❌
✅
Third-party SDK integration
Custom Animation
❌
✅
Complex Flutter animations
GPS Location
❌
✅
Native location services
Charts/Graphs
❌
✅
Third-party charting library
File Picker
❌
✅
Native file system access
Status Badges
❌
✅
Custom styling requirements
Progress Indicators
✅
❌
Available in Digia UI
Modal Dialogs
✅
❌
Standard modal components
Implementation Pattern
1. Props Class
Define a class to handle data passed from Digia Studio:
2. Widget Class
Create the widget that extends VirtualLeafStatelessWidget:
3. Widget Implementation
The actual Flutter widget implementation:
4. Registration
Register the widget with Digia UI:
5. App Initialization
Method 1: Using DigiaUIAppBuilder (Recommended)
Register widgets after DigiaUIAppBuilder initialization:
Method 2: Using DigiaUIApp with Manual Registration
For more control over initialization timing:
Usage in Digia Studio
Once registered, widgets appear in Digia Studio's component palette:
Advanced Patterns
Stateful Widgets
For widgets that need internal state:
Integration with Analytics
Send analytics events from custom widgets:
Accessing Native Services
Use custom widgets to access device features:
Best Practices
1. Keep Widgets Focused
Each widget should have a single responsibility
Avoid complex state management within widgets
Use props for configuration, not behavior
2. Handle Props Safely
Always validate props in
fromJsonProvide sensible defaults
Handle null/undefined values gracefully
3. Use Proper Naming
Widget IDs should be unique and descriptive
Use kebab-case for IDs:
custom/my-widget-nameFollow Flutter naming conventions for classes
4. Test Thoroughly
Test in both native and Digia contexts
Verify props parsing works correctly
Test event handling through message bus
5. Document Your Widgets
Include clear prop descriptions
Provide usage examples
Document event behaviors
Common Patterns
Payment Integration
Map Integration
File Picker
Troubleshooting
Widget Not Appearing in Digia Studio
Check that registration is called before Digia UI initialization
Verify the widget ID matches exactly in Digia Studio
Ensure props parsing doesn't throw exceptions
Props Not Working
Check
fromJsonmethod for correct parsingVerify prop names match Digia Studio configuration
Add debug prints to see what props are received
Events Not Firing
Ensure message bus is properly initialized
Check channel names match between widget and handler
Verify Digia Studio event configuration
Example: Complete Custom Widget
See the ProductHub demo for a complete working example of custom widget implementation, including:
DeliveryTypeStatuswidget with custom stylingAnalytics integration
Message bus communication
Registration and usage patterns
Last updated