jaspr_flutter_embed package allows you to embed Flutter widgets directly into your Jaspr web applications, combining the best of both frameworks.
Overview
Flutter embedding enables you to:- Use Flutter’s rich widget ecosystem in web apps
- Leverage existing Flutter widgets and packages
- Create hybrid applications with Jaspr HTML and Flutter UI
- Gradually migrate Flutter widgets to Jaspr components
Installation
Add the dependency to yourpubspec.yaml:
Basic Usage
Use theFlutterEmbedView component to embed Flutter widgets:
FlutterEmbedView Properties
TheFlutterEmbedView component accepts several properties:
Deferred Loading
For better performance, load Flutter widgets lazily using deferred imports:Preloading Flutter
Preload the Flutter engine before rendering:View Constraints
Control the size and layout of embedded Flutter widgets:Styling the Container
Style the container element using CSS:Communication Between Jaspr and Flutter
Passing Data to Flutter
Create Flutter widgets that accept parameters:Using State Management
Share state between Jaspr and Flutter using providers:Real-World Example
Here’s a complete example embedding a Flutter chart in a Jaspr dashboard:Platform Considerations
Conditional Platform Imports
Performance Tips
Preload the Flutter engine
Call
FlutterEmbedView.preload() early to initialize Flutter in the background.Limit embedded widgets
Don’t embed too many Flutter widgets on a single page - they each require resources.
Troubleshooting
Flutter widget not rendering:- Ensure container has explicit width/height
- Check browser console for Flutter initialization errors
- Verify Flutter SDK is properly installed
- Use deferred loading for large Flutter widgets
- Limit the number of embedded widgets per page
- Consider using Jaspr components instead for simple UI
- Flutter uses its own styling system
- Isolate Flutter widgets in containers with explicit dimensions
- Use Flutter’s theming for Flutter widgets, Jaspr styles for HTML elements