pub package


A Flutter widget to embed vega-lite charts to flutter web and flutter apps using webview_flutter. Works consistently in Flutter web as of now. SInternally it uses vega-embed js library to embed these specs using JS interops and HTMLElementView.

A Demo page with examples for different vega-embed options is available below.

A demo page

A full fledged demo page with various charts utilizing this package is avalaible here

Demo Page Gif

Since flutter web_view is still in developer preview, vega_embed_flutter's web_view support should also be considered as a developer preview. Flutter web view demo


This widget is made possible only because of the great works done by the team behind vega-embed, vega-Lite and vega. For a detailed documentation of how visualize using Vega-lite specs please head to their doumentation page.

General Setup Steps for flutter web

Import Vega related Javascript files.

Start by adding the script tag for vega related java script files. For example.


<!DOCTYPE html>
    <meta charset="UTF-8" />
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src="main.dart.js" type="application/javascript"></script>

Add your vega lite specification files

Vega-Lite and Vega defines its visualsation in the form of json file. So for you project it would be easy to maintain all this vega-lite spec files in a folder say vega_lite_specs folder. For example

              |_ bart_chart.json
              |_ interactive_multiline_plot.json
              |_ interactive_splom.json

Add assets entry in pupspec.yaml

In order for the web build to pick up the json schemas add it your pubspec.yaml. For e.g.

  uses-material-design: true
  # This line includes all the files these directories during the build process
  # and placess them under build/web/assets folder.
    - vega_lite_specs/

Import the file and use the widget

Just import the vega_embed_flutter library as below

import 'package:vega_embed_flutter/vega_embed_flutter.dart';

Create a normal stateless/ful widget and use it as a normal stateless/ful widget.

class BarChart extends StatelessWidget {
  Widget build(BuildContext context) {
    return VegaLiteEmbedder(
      viewFactoryId: 'MyBarChart',
      vegaLiteSpecLocation: '/assets/vega_lite_specs/bar_chart.json',

General set for normal flutter app

Follow the Add your vega lite schema files section and Add assets entry in pupspec.yaml as mentioned above.

Import web view specific file and use the widget

Import the vega embed view specific librarys as below import 'package:vega_embed_flutter/vega_embed_webview.dart';

Create a normal stateless/ful widget and use it as a normal stateless/ful widget.

class ExampleWebViewApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SafeArea(
        child: Center(
          child: Column(
            children: [
                child: VegaLiteWebViewEmbedder(
                  vegaLiteSpecLocation: 'vega_lite_specs/bar_chart copy.json',
                child: VegaLiteWebViewEmbedder(
                  vegaEmbedOptions: VegaEmbedOptions(theme: 'dark'),

VegaEmbed Options WIP(available only for web)

Following vega-embed options are tested and are available as part of demo page. If you need further comprehensive options to be tested or enabled please do raise and issue so that I can spend time on options which are necessary.

For a detailed description of what each vega embed options check this page.

Embed OptionsWorkingComments
mode:construction:Avialble but not tested.
theme:100:Check here for detials on the themes. Valid values are excel, ggplot2, quartz, vox, fivethirtyeight , dark, latimes, urbaninstitute, googlecharts
tooltip:thinking:Let me know if you need it
width:heavy_check_mark:Note: :warning: width mentioned in spec overrides this.
height:heavy_check_mark:Note: :warning: Height mentioned in spec overrides this.
actions:construction:Note: :warning: an example is shown to remove actions. But its not complete to spec.
scaleFactor:heavy_check_mark:Note: This is a scale factor for the exported file, not the plot.
config:thinking:Let me know if you need it. Porting config object to dart will take lot of effort to test.
editorUrl:construction:Avialble but not tested.
sourceHeader:construction:Avialble but not tested.
sourceFooter:construction:Avialble but not tested.
hover:thinking:Let me know if you need it.
formatLocale:construction:Avialble but not tested.
timeFormatLocale:construction:Avialble but not tested.

Any kind of code, idea, suggestions are welcome. Please check the repository and file your feedbacks and bugs which is highly appreciated.