Skip to content

Commit

Permalink
v2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
entronad committed Aug 31, 2023
1 parent e7ff142 commit 606235d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 44 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.5.0

**2023-08-31**

- Upgrade webview_flutter to 4.2.4
- Upgrade Echarts to 5.4.3
- Upgrade SDK to >=2.12.0 <4.0.0

## 2.4.0

**2022-08-13**
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
48 changes: 46 additions & 2 deletions lib/echarts_script.dart

Large diffs are not rendered by default.

68 changes: 30 additions & 38 deletions lib/flutter_echarts.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
library flutter_echarts;

import 'dart:convert';

import 'package:flutter/widgets.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/foundation.dart';

import 'package:webview_flutter/webview_flutter.dart';

import 'echarts_script.dart' show echartsScript;

/// <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, target-densitydpi=device-dpi" /><style type="text/css">body,html,#chart{height: 100%;width: 100%;margin: 0px;}div {-webkit-tap-highlight-color:rgba(255,255,255,0);}</style></head><body><div id="chart" /></body></html>
/// 'data:text/html;base64,' + base64Encode(const Utf8Encoder().convert( /* STRING ABOVE */ ))
const htmlBase64 =
'data:text/html;base64,PCFET0NUWVBFIGh0bWw+PGh0bWw+PGhlYWQ+PG1ldGEgY2hhcnNldD0idXRmLTgiPjxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgsIGluaXRpYWwtc2NhbGU9MS4wLCBtYXhpbXVtLXNjYWxlPTEuMCwgbWluaW11bS1zY2FsZT0xLjAsIHVzZXItc2NhbGFibGU9MCwgdGFyZ2V0LWRlbnNpdHlkcGk9ZGV2aWNlLWRwaSIgLz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPmJvZHksaHRtbCwjY2hhcnR7aGVpZ2h0OiAxMDAlO3dpZHRoOiAxMDAlO21hcmdpbjogMHB4O31kaXYgey13ZWJraXQtdGFwLWhpZ2hsaWdodC1jb2xvcjpyZ2JhKDI1NSwyNTUsMjU1LDApO308L3N0eWxlPjwvaGVhZD48Ym9keT48ZGl2IGlkPSJjaGFydCIgLz48L2JvZHk+PC9odG1sPg==';
'PCFET0NUWVBFIGh0bWw+PGh0bWw+PGhlYWQ+PG1ldGEgY2hhcnNldD0idXRmLTgiPjxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgsIGluaXRpYWwtc2NhbGU9MS4wLCBtYXhpbXVtLXNjYWxlPTEuMCwgbWluaW11bS1zY2FsZT0xLjAsIHVzZXItc2NhbGFibGU9MCwgdGFyZ2V0LWRlbnNpdHlkcGk9ZGV2aWNlLWRwaSIgLz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPmJvZHksaHRtbCwjY2hhcnR7aGVpZ2h0OiAxMDAlO3dpZHRoOiAxMDAlO21hcmdpbjogMHB4O31kaXYgey13ZWJraXQtdGFwLWhpZ2hsaWdodC1jb2xvcjpyZ2JhKDI1NSwyNTUsMjU1LDApO308L3N0eWxlPjwvaGVhZD48Ym9keT48ZGl2IGlkPSJjaGFydCIgLz48L2JvZHk+PC9odG1sPg==';

class Echarts extends StatefulWidget {
Echarts(
Expand Down Expand Up @@ -65,6 +66,26 @@ class _EchartsState extends State<Echarts> {
super.initState();
_currentOption = widget.option;

_controller = WebViewController()
..setBackgroundColor(Color(0x00000000))
..loadHtmlString(utf8.fuse(base64).decode(htmlBase64))
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onPageFinished: (url) => init(),
onWebResourceError: (e) {
if (widget.onWebResourceError != null) {
widget.onWebResourceError!(_controller!, Exception(e));
}
},
),
)
..addJavaScriptChannel('Messager', onMessageReceived: (JavaScriptMessage javascriptMessage) {
if (widget.onMessage != null) {
widget.onMessage!(javascriptMessage.message);
}
});

if (widget.reloadAfterInit) {
new Future.delayed(const Duration(milliseconds: 100), () {
_controller?.reload();
Expand All @@ -73,15 +94,9 @@ class _EchartsState extends State<Echarts> {
}

void init() async {
final extensionsStr = this.widget.extensions.length > 0
? this
.widget
.extensions
.reduce((value, element) => value + '\n' + element)
: '';
final themeStr =
this.widget.theme != null ? '\'${this.widget.theme}\'' : 'null';
await _controller?.runJavascript('''
final extensionsStr = this.widget.extensions.length > 0 ? this.widget.extensions.reduce((value, element) => value + '\n' + element) : '';
final themeStr = this.widget.theme != null ? '\'${this.widget.theme}\'' : 'null';
await _controller?.runJavaScript('''
$echartsScript
$extensionsStr
var chart = echarts.init(document.getElementById('chart'), $themeStr);
Expand All @@ -95,8 +110,7 @@ class _EchartsState extends State<Echarts> {

Set<Factory<OneSequenceGestureRecognizer>> getGestureRecognizers() {
Set<Factory<OneSequenceGestureRecognizer>> set = Set();
if (this.widget.captureAllGestures ||
this.widget.captureHorizontalGestures) {
if (this.widget.captureAllGestures || this.widget.captureHorizontalGestures) {
set.add(Factory<HorizontalDragGestureRecognizer>(() {
return HorizontalDragGestureRecognizer()
..onStart = (DragStartDetails details) {}
Expand All @@ -122,7 +136,7 @@ class _EchartsState extends State<Echarts> {
void update(String preOption) async {
_currentOption = widget.option;
if (_currentOption != preOption) {
await _controller?.runJavascript('''
await _controller?.runJavaScript('''
try {
chart.setOption($_currentOption, true);
} catch(e) {
Expand All @@ -145,30 +159,8 @@ class _EchartsState extends State<Echarts> {

@override
Widget build(BuildContext context) {
return WebView(
backgroundColor: Color(0x00000000),
initialUrl: htmlBase64,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller = webViewController;
},
onPageFinished: (String url) {
init();
},
onWebResourceError: (e) {
if (widget.onWebResourceError != null) {
widget.onWebResourceError!(_controller!, Exception(e));
}
},
javascriptChannels: <JavascriptChannel>[
JavascriptChannel(
name: 'Messager',
onMessageReceived: (JavascriptMessage javascriptMessage) {
if (widget.onMessage != null) {
widget.onMessage!(javascriptMessage.message);
}
}),
].toSet(),
return WebViewWidget(
controller: _controller!,
gestureRecognizers: getGestureRecognizers());
}
}
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: flutter_echarts
description: A data visualization charts library, based on Apache ECharts, able to build advanced charts like WebGL 3D, GIS map, etc.
version: 2.4.0
version: 2.5.0
homepage: https://github.com/entronad/flutter_echarts

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.12.0 <4.0.0"

dependencies:
flutter:
sdk: flutter
webview_flutter: ^3.0.4
webview_flutter: ^4.2.4

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 606235d

Please sign in to comment.