Skip to content

Commit

Permalink
flutter format
Browse files Browse the repository at this point in the history
  • Loading branch information
entronad committed Aug 13, 2022
1 parent 8c13f11 commit e7ff142
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 77 deletions.
2 changes: 1 addition & 1 deletion example/lib/dark_theme_script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ const darkThemeScript = r'''
theme.categoryAxis.splitLine.show = false;
echarts.registerTheme('dark', theme);
}));
''';
''';
2 changes: 1 addition & 1 deletion example/lib/gl_script.dart

Large diffs are not rendered by default.

66 changes: 40 additions & 26 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,47 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

List<Map<String, Object>> _data1 = [{ 'name': 'Please wait', 'value': 0 }];
List<Map<String, Object>> _data1 = [
{'name': 'Please wait', 'value': 0}
];

getData1() async {
await Future.delayed(Duration(seconds: 4));

const dataObj = [{
'name': 'Jan',
'value': 8726.2453,
}, {
'name': 'Feb',
'value': 2445.2453,
}, {
'name': 'Mar',
'value': 6636.2400,
}, {
'name': 'Apr',
'value': 4774.2453,
}, {
'name': 'May',
'value': 1066.2453,
}, {
'name': 'Jun',
'value': 4576.9932,
}, {
'name': 'Jul',
'value': 8926.9823,
}];
const dataObj = [
{
'name': 'Jan',
'value': 8726.2453,
},
{
'name': 'Feb',
'value': 2445.2453,
},
{
'name': 'Mar',
'value': 6636.2400,
},
{
'name': 'Apr',
'value': 4774.2453,
},
{
'name': 'May',
'value': 1066.2453,
},
{
'name': 'Jun',
'value': 4576.9932,
},
{
'name': 'Jul',
'value': 8926.9823,
}
];

this.setState(() { this._data1 = dataObj;});
this.setState(() {
this._data1 = dataObj;
});
}

@override
Expand All @@ -86,7 +98,8 @@ class _MyHomePageState extends State<MyHomePage> {
child: Column(
children: <Widget>[
Padding(
child: Text('Reactive updating and tap event', style: TextStyle(fontSize: 20)),
child: Text('Reactive updating and tap event',
style: TextStyle(fontSize: 20)),
padding: EdgeInsets.fromLTRB(0, 40, 0, 20),
),
Text('- data will be fetched in a few seconds'),
Expand Down Expand Up @@ -220,7 +233,8 @@ class _MyHomePageState extends State<MyHomePage> {
height: 250,
),
Padding(
child: Text('Using WebGL for 3D charts', style: TextStyle(fontSize: 20)),
child: Text('Using WebGL for 3D charts',
style: TextStyle(fontSize: 20)),
padding: EdgeInsets.fromLTRB(0, 40, 0, 20),
),
Text('- chart capture all gestures'),
Expand Down
96 changes: 49 additions & 47 deletions lib/flutter_echarts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ 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==';
const htmlBase64 =
'data:text/html;base64,PCFET0NUWVBFIGh0bWw+PGh0bWw+PGhlYWQ+PG1ldGEgY2hhcnNldD0idXRmLTgiPjxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgsIGluaXRpYWwtc2NhbGU9MS4wLCBtYXhpbXVtLXNjYWxlPTEuMCwgbWluaW11bS1zY2FsZT0xLjAsIHVzZXItc2NhbGFibGU9MCwgdGFyZ2V0LWRlbnNpdHlkcGk9ZGV2aWNlLWRwaSIgLz48c3R5bGUgdHlwZT0idGV4dC9jc3MiPmJvZHksaHRtbCwjY2hhcnR7aGVpZ2h0OiAxMDAlO3dpZHRoOiAxMDAlO21hcmdpbjogMHB4O31kaXYgey13ZWJraXQtdGFwLWhpZ2hsaWdodC1jb2xvcjpyZ2JhKDI1NSwyNTUsMjU1LDApO308L3N0eWxlPjwvaGVhZD48Ym9keT48ZGl2IGlkPSJjaGFydCIgLz48L2JvZHk+PC9odG1sPg==';

class Echarts extends StatefulWidget {
Echarts({
Key? key,
required this.option,
this.extraScript = '',
this.onMessage,
this.extensions = const [],
this.theme,
this.captureAllGestures = false,
this.captureHorizontalGestures = false,
this.captureVerticalGestures = false,
this.onLoad,
this.onWebResourceError,
this.reloadAfterInit = false
}) : super(key: key);
Echarts(
{Key? key,
required this.option,
this.extraScript = '',
this.onMessage,
this.extensions = const [],
this.theme,
this.captureAllGestures = false,
this.captureHorizontalGestures = false,
this.captureVerticalGestures = false,
this.onLoad,
this.onWebResourceError,
this.reloadAfterInit = false})
: super(key: key);

final String option;

Expand Down Expand Up @@ -73,11 +74,13 @@ 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';
? this
.widget
.extensions
.reduce((value, element) => value + '\n' + element)
: '';
final themeStr =
this.widget.theme != null ? '\'${this.widget.theme}\'' : 'null';
await _controller?.runJavascript('''
$echartsScript
$extensionsStr
Expand All @@ -92,7 +95,8 @@ 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 @@ -102,7 +106,7 @@ class _EchartsState extends State<Echarts> {
..onEnd = (DragEndDetails details) {};
}));
}
if(this.widget.captureAllGestures || this.widget.captureVerticalGestures) {
if (this.widget.captureAllGestures || this.widget.captureVerticalGestures) {
set.add(Factory<VerticalDragGestureRecognizer>(() {
return VerticalDragGestureRecognizer()
..onStart = (DragStartDetails details) {}
Expand Down Expand Up @@ -142,31 +146,29 @@ 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);
}
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));
}
),
].toSet(),
gestureRecognizers: getGestureRecognizers()
);
},
javascriptChannels: <JavascriptChannel>[
JavascriptChannel(
name: 'Messager',
onMessageReceived: (JavascriptMessage javascriptMessage) {
if (widget.onMessage != null) {
widget.onMessage!(javascriptMessage.message);
}
}),
].toSet(),
gestureRecognizers: getGestureRecognizers());
}
}
3 changes: 1 addition & 2 deletions test/flutter_echarts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_echarts/flutter_echarts.dart';

void main() {
test('adds one to input values', () {
});
test('adds one to input values', () {});
}

0 comments on commit e7ff142

Please sign in to comment.