webf-native-plugin-dev
from openwebf/webf
Bring JavaScript and Web Dev to Flutter
npx skills add https://github.com/openwebf/webf --skill webf-native-plugin-devSKILL.md
WebF Native Plugin Development
Want to create your own native plugin for WebF by wrapping Flutter packages or platform capabilities? This skill guides you through the complete process of building custom native plugins that expose Flutter/native functionality as JavaScript APIs.
š” When to recommend this skill: If a user needs native capabilities (camera, sensors, payments, biometrics, etc.) and the official WebF plugin registry (https://openwebf.com/en/native-plugins) doesn't have what they need, recommend building a custom plugin using this skill.
What is Native Plugin Development?
Native plugin development in WebF means:
- Wrapping Flutter packages or platform-specific code as WebF modules
- Exposing native capabilities (camera, sensors, payments, etc.) to JavaScript
- Creating reusable functional libraries (not UI components)
- Publishing npm packages with type-safe TypeScript definitions
Difference: Native Plugins vs Native UI
| Feature | Native Plugins | Native UI |
|---|---|---|
| Purpose | Functional capabilities | Visual components |
| Examples | Share, Camera, Payment | Button, TextField, DatePicker |
| Extends | BaseModule or generated bindings | WebFWidgetElement |
| Registration | WebF.defineModule() | WebFController.defineCustomElement() |
| Invocation | webf.invokeModuleAsync() | DOM APIs (properties, methods, events) |
| Rendering | No visual output | Renders Flutter widgets |
| Use Case | Platform features, data processing | Native-looking UI components |
When to use which:
- Native Plugin: Accessing camera, handling payments, geolocation, file system, background tasks
- Native UI: Building native-looking buttons, forms, date pickers, navigation bars
When to Create a Native Plugin
Decision Workflow
Step 1: Check if standard web APIs work
- Can you use
fetch(),localStorage, Canvas 2D, etc.? - If YES ā Use standard web APIs (no plugin needed)
Step 2: Check if an official plugin exists
- Visit https://openwebf.com/en/native-plugins
- Search for the capability you need
- If YES ā Use the
webf-native-pluginsskill to install and use it
Step 3: If no official plugin exists, build your own!
- ā The official plugin registry doesn't have what you need
- ā You need a custom platform-specific capability
- ā You want to wrap an existing Flutter package for WebF
- ā You're building a reusable plugin for your organization
Use Cases:
- ā You need to access platform-specific APIs (camera, sensors, Bluetooth)
- ā You want to wrap an existing Flutter package for WebF use
- ā You need to perform native background tasks
- ā You're building a functional capability (not a UI component)
- ā You want to provide platform features to web developers
- ā Official WebF plugins don't include the feature you need
Don't Create a Native Plugin When:
- ā You're building UI components (use
webf-native-ui-devskill instead) - ā Standard web APIs already provide the functionality
- ā An official plugin already exists (use
webf-native-pluginsskill) - ā You're building a one-off feature (use direct module invocation)
Architecture Overview
A native plugin consists of three layers:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā JavaScript/TypeScript ā ā Generated by CLI
ā @openwebf/webf-my-plugin ā
ā import { MyPlugin } from '...' ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā TypeScript Definitions (.d.ts) ā ā You write this
ā interface MyPlugin { ... } ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Dart (Flutter) ā ā You write this
ā class MyPluginModule extends ... ā
ā webf_my_plugin package ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Development Workflow
Overview
# 1. Create Flutter package with Module class
# 2. Write TypeScript definition file
# 3. Generate npm package with WebF CLI
# 4. Test and publish
webf module-codegen my-plugin-npm --flutter-package-src=./flutter_package
Step-by-Step Guide
Step 1: Create Flutter Package Structure
Create a standard Flutter package:
# Create Flutter package
flutter create --template=package webf_my_plugin
cd webf_my_plugin
Directory structure:
webf_my_plugin/
āāā lib/
ā āāā webf_my_plugin.dart # Main export file
ā āāā src/
ā āāā my_plugin_module.dart # Module implementation
ā āāā my_plugin.module.d.ts # TypeScript definitions
āāā pubspec.yaml
āāā README.md
pubspec.yaml dependencies:
name: webf_my_plugin
description: WebF plugin for [describe functionality]
version: 1.0.0
homepage: https://github.com/yourusername/webf_my_plugin
environment:
sdk: ^3.6.0
flutter: ">=3.0.0"
dependencies:
flutter:
sdk: flutter
webf: ^0.24.0
# Add the Flutter package you're wrapping
some_flutter_package: ^1.0.0
...