diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index a060db6..e3336b8 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -41,5 +41,10 @@ UIViewControllerBasedStatusBarAppearance + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + diff --git a/example/pubspec.lock b/example/pubspec.lock index f20dd1d..11b5882 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -62,13 +62,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_inappwebview: - dependency: transitive - description: - name: flutter_inappwebview - url: "https://pub.dartlang.org" - source: hosted - version: "5.3.2" flutter_test: dependency: "direct dev" description: flutter @@ -179,4 +172,4 @@ packages: version: "2.0.7" sdks: dart: ">=2.12.0 <3.0.0" - flutter: ">=1.22.2" + flutter: ">=1.22.0" diff --git a/lib/src/models/button.dart b/lib/src/models/button.dart index 95c674d..0b9e030 100644 --- a/lib/src/models/button.dart +++ b/lib/src/models/button.dart @@ -2,7 +2,8 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class Button { - IconData icon; + IconData? icon; + Function? onTap; - Button({this.icon = Icons.format_bold}); + Button({this.icon, this.onTap}); } diff --git a/lib/src/rendering/rich_editor.dart b/lib/src/rendering/rich_editor.dart index 2b13199..936abb6 100644 --- a/lib/src/rendering/rich_editor.dart +++ b/lib/src/rendering/rich_editor.dart @@ -14,6 +14,7 @@ class _RichEditorState extends State { WebViewController? _controller; String text = ""; final Key _mapKey = UniqueKey(); + String assetPath = 'packages/rich_editor/assets/editor/editor.html'; int port = 5321; LocalServer? localServer; @@ -22,6 +23,41 @@ class _RichEditorState extends State { void initState() { super.initState(); if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); + if (!Platform.isAndroid) { + initServer(); + } + } + + initServer() { + localServer = LocalServer(port); + localServer!.start(handleRequest); + } + + void handleRequest(HttpRequest request) { + try { + if (request.method == 'GET' && + request.uri.queryParameters['query'] == "getRawTeXHTML") { + } else {} + } catch (e) { + print('Exception in handleRequest: $e'); + } + } + + + @override + void dispose() { + if (_controller != null) { + _controller = null; + } + if (!Platform.isAndroid) { + localServer!.close(); + } + super.dispose(); + } + + _loadHtmlFromAssets() async { + final filePath = assetPath; + _controller!.loadUrl("http://localhost:$port/$filePath"); } @override @@ -31,14 +67,24 @@ class _RichEditorState extends State { GroupedTab(controller: _controller), Flexible( child: WebView( - initialUrl: - 'file:///android_asset/flutter_assets/packages/rich_editor/assets/editor/editor.html', + key: _mapKey, + // initialUrl: + // 'file:///android_asset/flutter_assets/packages/rich_editor/assets/editor/editor.html', onWebViewCreated: (WebViewController controller) { _controller = controller; print('WebView created'); setState(() {}); + if (!Platform.isAndroid) { + print('Loading'); + _loadHtmlFromAssets(); + } else { + _controller!.loadUrl('file:///android_asset/flutter_assets/$assetPath'); + } }, javascriptMode: JavascriptMode.unrestricted, + onWebResourceError: (e) { + print("error ${e.description}"); + }, ), // child: InAppWebView( // initialFile: 'packages/rich_editor/assets/editor/index.html', diff --git a/lib/src/utils/constants.dart b/lib/src/utils/constants.dart index d7c2443..b9557a3 100644 --- a/lib/src/utils/constants.dart +++ b/lib/src/utils/constants.dart @@ -1,32 +1,144 @@ import 'package:flutter/material.dart'; import 'package:rich_editor/src/models/button.dart'; +import 'javascript_executor_base.dart'; + List