Add WebF to Flutter
This guide is for Flutter developers who want to integrate WebF into their existing Flutter applications to leverage web technologies, reuse WebF app code, or create powerful hybrid user interfaces.
What is WebF?
WebF is a high-performance web rendering engine built on Flutter that enables you to build native Flutter apps using web technologies (HTML, CSS, and JavaScript). Unlike traditional webviews, WebF directly renders WebF app content using Flutter’s rendering pipeline, providing native-like performance and seamless integration with Flutter widgets.
What is a WebF App?
A WebF app consists of two complementary parts:
-
Web Standards Layer: Standard HTML, CSS, and JavaScript code that’s compatible with web standards
- Works with popular frameworks like React, Vue, and vanilla JS
- Uses familiar DOM APIs, CSS styling, and JavaScript features
- Portable and can run in browsers with minimal modifications
-
Flutter Integration Layer: Custom APIs, components, and services exposed from Flutter
- Custom Elements: Flutter widgets accessible as HTML elements (e.g.,
<flutter-button>) - Native Modules: Dart/Flutter APIs callable from JavaScript (e.g., camera, storage, sensors)
- Platform Features: Access to device capabilities through Flutter plugins
- Custom Elements: Flutter widgets accessible as HTML elements (e.g.,
This hybrid architecture lets you leverage both the web ecosystem and Flutter’s native capabilities in a single WebF application.
Key Characteristics
- Not a browser: WebF builds Flutter apps, not WebF apps running in browsers
- Native rendering: Uses Flutter’s rendering engine, not browser rendering
- JavaScript runtime: Powered by QuickJS for efficient JS execution
- Web standards support: Implements core DOM/CSS APIs with C++ and Dart
- Hybrid UI: Mix Flutter widgets and WebF app content seamlessly
Why Integrate WebF into a Flutter App?
WebF unlocks powerful capabilities for Flutter developers:
- Leverage Web Ecosystem: Use popular web frameworks like React, Vue, and their vast ecosystem of libraries
- Code Reuse: Share code and components between web and mobile without maintaining separate codebases
- Hot Updates: Update UI and logic over-the-air without app store approvals (within platform guidelines)
- Rapid Prototyping: Build complex UIs faster using familiar web technologies
- Hybrid Teams: Enable web developers to contribute to mobile apps
- Dynamic Content: Load and render dynamic WebF app content safely
- Cross-Platform UI: Write once in React/Vue, run on iOS, Android, macOS, Linux, and Windows
Use Cases
- Building feature-rich apps with frequent updates
- Creating content-driven WebF applications (news, blogs, e-commerce)
- Integrating WebF app-based admin panels or dashboards
- Developing apps with complex, dynamic layouts
- Sharing business logic between web and mobile platforms
Getting Started
This guide is organized into several sections to help you integrate WebF into your Flutter application:
Integration Guide
- Getting Started - Install WebF and create your first instance
- Core Concepts - Understand WebF widgets, controllers, and lifecycle
- Embedding WebF - Integrate WebF into your widget tree
- Hybrid UI - Create custom Flutter widgets for WebF
- Build Native Plugins - Expose Flutter plugins to JavaScript
- Hybrid Routing - Set up navigation between Flutter and WebF
- Advanced Topics - Performance monitoring, theming, and caching
Deployment
Once you have integrated WebF into your Flutter app, deploy it like any standard Flutter app:
- Deployment Guide - Deploy your WebF Flutter app to app stores and manage WebF app content updates
Quick Example
Here’s a minimal example to get you started:
import 'package:flutter/material.dart';
import 'package:webf/webf.dart';
void main() {
// Initialize WebF controller manager
WebFControllerManager.instance.initialize(
WebFControllerManagerConfig(
maxAliveInstances: 5,
maxAttachedInstances: 3,
),
);
// Pre-render a WebF app
WebFControllerManager.instance.addWithPrerendering(
name: 'home',
createController: () => WebFController(),
bundle: WebFBundle.fromUrl('https://example.com/'),
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: WebF.fromControllerName(
controllerName: 'home',
loadingWidget: CircularProgressIndicator(),
),
),
);
}
}Prerequisites
Before integrating WebF, ensure you have:
- Flutter SDK (latest stable version recommended)
- Basic understanding of Flutter widgets and state management
- (Optional) Familiarity with web technologies (HTML, CSS, JavaScript)
- (Optional) Experience with React or Vue for building WebF apps
Next Steps
Start with the Getting Started guide to install WebF and create your first instance.
Additional Resources
- GitHub: https://github.com/openwebf/webf
- Documentation: https://webf.dev
- Discord Community: https://discord.gg/DvUBtXZ5rK
- API Docs: https://pub.dev/documentation/webf/latest/
Contributing
WebF is open source! Contributions are welcome:
- Report issues: https://github.com/openwebf/webf/issues
- Submit PRs: https://github.com/openwebf/webf/pulls
- Join discussions: https://github.com/openwebf/webf/discussions