superset_bridge 1.8.0
superset_bridge: ^1.8.0 copied to clipboard
A Flutter package that embeds Apache Superset dashboards inside a WebView with automatic dark/light theme support. Applies a CSS filter technique to work around cross-origin iframe restrictions.
superset_bridge #
A Flutter package that embeds Apache Superset dashboards inside a WebView with automatic dark/light theme support and a flexible configuration API. It uses a CSS filter hack to apply dark mode on cross-origin iframes and exposes a Dart controller for easy integration.
The package is published on pub.dev
and can be added to any Flutter project that uses a WebView (currently
flutter_inappwebview).
Features #
- Generate self-contained HTML string containing Superset embed code using a JSON-serialisable configuration object.
- Toggle dark/light mode without reloading the WebView.
- Optional token fetch or manual token injection.
- Specify a top‑level
languageCodethat will be sent as thelangURL parameter (in addition to or instead of usingextraUrlParams). - Pass arbitrary extra URL parameters (via
SupersetBridgeConfig.extraUrlParams) so each project can customise the embed request without modifying the package.
Getting started #
- Add dependency
dependencies:
superset_bridge: ^1.6.0
- Import the package
import 'package:superset_bridge/superset_bridge.dart';
- Create a controller and generate HTML
final bridge = SupersetBridgeController();
final config = SupersetBridgeConfig(
dashboardId: 'your-dashboard-uuid',
domain: 'https://superset.example.com',
theme: 'light',
languageCode: 'en', // optional first‑class language parameter
siteIds: [1, 2], // optional
extraUrlParams: {
'orgId': 42,
},
);
final html = SupersetBridgeHtmlContent.generate(config);
- Load the HTML into a WebView (using
flutter_inappwebview):
InAppWebView(
initialData: InAppWebViewInitialData(
data: html,
mimeType: 'text/html',
encoding: 'utf-8',
),
onWebViewCreated: (controller) {
bridge.attach(controller);
},
);
- Update theme or config dynamically
// simple theme switch without a full reload:
await bridge.updateUI(theme: 'dark');
// regenerate HTML with new config (e.g. new dashboardId or language):
final newHtml = SupersetBridgeHtmlContent.generate(
config.copyWith(theme: 'dark', languageCode: 'fr'),
);
await bridge.reload(newHtml);
- Advanced embedding
If you already have a guest token from your backend, use the init methods:
await bridge.init(
config,
token: 'pre_fetched_token',
);
or
await bridge.initWithTokenFetch(config);
Both methods accept a SupersetBridgeConfig object.
Migration from inline code #
Previously you might have manually copied the HTML generator and controller
into your project; those files are still present in this repo for reference but
are not required anymore. Simply depend on the package and update your code to
use the exported SupersetBridgeConfig, SupersetBridgeHtmlContent, and
SupersetBridgeController classes.
Publishing to pub.dev #
- Ensure version and changelog are updated in
pubspec.yamlandCHANGELOG.md. - Run
dart pub publish --dry-runto validate the package; fix any issues. - Run
dart pub publishand sign in with your Google (pub.dev) account. - After successful upload, bump the version in
pubspec.yamland commit the changes.
Once published you can install the package in any Flutter app by adding the version constraint as shown above.
License #
The package is released under the MIT license.
For full examples, see the example/ directory in the GitHub repository.