webf-native-plugin-dev

from openwebf/webf

Bring JavaScript and Web Dev to Flutter

2.3K stars154 forksUpdated Jan 26, 2026
npx skills add https://github.com/openwebf/webf --skill webf-native-plugin-dev

SKILL.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

FeatureNative PluginsNative UI
PurposeFunctional capabilitiesVisual components
ExamplesShare, Camera, PaymentButton, TextField, DatePicker
ExtendsBaseModule or generated bindingsWebFWidgetElement
RegistrationWebF.defineModule()WebFController.defineCustomElement()
Invocationwebf.invokeModuleAsync()DOM APIs (properties, methods, events)
RenderingNo visual outputRenders Flutter widgets
Use CasePlatform features, data processingNative-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

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-dev skill instead)
  • āŒ Standard web APIs already provide the functionality
  • āŒ An official plugin already exists (use webf-native-plugins skill)
  • āŒ 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

...

Read full content

Repository Stats

Stars2.3K
Forks154
LicenseGNU General Public License v3.0