refactor: used flutter_inappwebview instead of webview_flutter
This commit is contained in:
parent
0ba6803269
commit
7677e120cc
@ -73,6 +73,9 @@ Clear Editor content
|
||||
await keyEditor.currentState?.clear();
|
||||
```
|
||||
|
||||
### Custom Toolbar
|
||||
If you're interested in creating your own toolbar check the custom_toolbar_demo.dart in the example
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2021 JideGuru
|
||||
|
@ -1,7 +1,15 @@
|
||||
PODS:
|
||||
- Flutter (1.0.0)
|
||||
- flutter_inappwebview (0.0.1):
|
||||
- Flutter
|
||||
- flutter_inappwebview/Core (= 0.0.1)
|
||||
- OrderedSet (~> 5.0)
|
||||
- flutter_inappwebview/Core (0.0.1):
|
||||
- Flutter
|
||||
- OrderedSet (~> 5.0)
|
||||
- image_picker (0.0.1):
|
||||
- Flutter
|
||||
- OrderedSet (5.0.0)
|
||||
- video_player (0.0.1):
|
||||
- Flutter
|
||||
- wakelock (0.0.1):
|
||||
@ -11,14 +19,21 @@ PODS:
|
||||
|
||||
DEPENDENCIES:
|
||||
- Flutter (from `Flutter`)
|
||||
- flutter_inappwebview (from `.symlinks/plugins/flutter_inappwebview/ios`)
|
||||
- image_picker (from `.symlinks/plugins/image_picker/ios`)
|
||||
- video_player (from `.symlinks/plugins/video_player/ios`)
|
||||
- wakelock (from `.symlinks/plugins/wakelock/ios`)
|
||||
- webview_flutter (from `.symlinks/plugins/webview_flutter/ios`)
|
||||
|
||||
SPEC REPOS:
|
||||
trunk:
|
||||
- OrderedSet
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Flutter:
|
||||
:path: Flutter
|
||||
flutter_inappwebview:
|
||||
:path: ".symlinks/plugins/flutter_inappwebview/ios"
|
||||
image_picker:
|
||||
:path: ".symlinks/plugins/image_picker/ios"
|
||||
video_player:
|
||||
@ -30,7 +45,9 @@ EXTERNAL SOURCES:
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
|
||||
flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721
|
||||
image_picker: 50e7c7ff960e5f58faa4d1f4af84a771c671bc4a
|
||||
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
|
||||
video_player: 9cc823b1d9da7e8427ee591e8438bfbcde500e6e
|
||||
wakelock: d0fc7c864128eac40eba1617cb5264d9c940b46f
|
||||
webview_flutter: 9f491a9b5a66f2573946a389b2677987b0ff8c0b
|
||||
|
@ -62,29 +62,45 @@ class _CustomToolbarDemoState extends State<CustomToolbarDemo> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: RichEditor(
|
||||
key: keyEditor,
|
||||
body: Column(
|
||||
children: [
|
||||
Wrap(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.format_bold),
|
||||
onPressed: () {
|
||||
keyEditor.currentState!.javascriptExecutor.setBold();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: RichEditor(
|
||||
key: keyEditor,
|
||||
// value: '', // initial HTML data
|
||||
editorOptions: RichEditorOptions(
|
||||
placeholder: 'Start typing',
|
||||
// backgroundColor: Colors.blueGrey, // Editor's bg color
|
||||
// baseTextColor: Colors.white,
|
||||
// editor padding
|
||||
padding: EdgeInsets.symmetric(horizontal: 5.0),
|
||||
// font name
|
||||
baseFontFamily: 'sans-serif',
|
||||
// Position of the editing bar (BarPosition.TOP or BarPosition.BOTTOM)
|
||||
barPosition: BarPosition.TOP,
|
||||
),
|
||||
editorOptions: RichEditorOptions(
|
||||
placeholder: 'Start typing',
|
||||
// backgroundColor: Colors.blueGrey, // Editor's bg color
|
||||
// baseTextColor: Colors.white,
|
||||
// editor padding
|
||||
padding: EdgeInsets.symmetric(horizontal: 5.0),
|
||||
// font name
|
||||
baseFontFamily: 'sans-serif',
|
||||
// Position of the editing bar (BarPosition.TOP or BarPosition.BOTTOM)
|
||||
barPosition: BarPosition.CUSTOM,
|
||||
),
|
||||
|
||||
// You can return a Link (maybe you need to upload the image to your
|
||||
// storage before displaying in the editor or you can also use base64
|
||||
getImageUrl: (image) {
|
||||
String link = 'https://avatars.githubusercontent.com/u/24323581?v=4';
|
||||
String base64 = base64Encode(image.readAsBytesSync());
|
||||
String base64String = 'data:image/png;base64, $base64';
|
||||
return base64String;
|
||||
},
|
||||
// You can return a Link (maybe you need to upload the image to your
|
||||
// storage before displaying in the editor or you can also use base64
|
||||
getImageUrl: (image) {
|
||||
String link = 'https://avatars.githubusercontent.com/u/24323581?v=4';
|
||||
String base64 = base64Encode(image.readAsBytesSync());
|
||||
String base64String = 'data:image/png;base64, $base64';
|
||||
return base64String;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:example/basic.dart';
|
||||
import 'package:example/custom_toolbar_demo.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rich_editor/rich_editor.dart';
|
||||
|
||||
@ -18,6 +19,7 @@ class MyApp extends StatelessWidget {
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: BasicDemo(),
|
||||
// home: CustomToolbarDemo(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import wakelock_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
|
||||
}
|
||||
|
@ -184,7 +184,6 @@
|
||||
33CC10EB2044A3C60003C045 /* Resources */,
|
||||
33CC110E2044A8840003C045 /* Bundle Framework */,
|
||||
3399D490228B24CF009A79C7 /* ShellScript */,
|
||||
06400C234E158CC19ED60959 /* [CP] Embed Pods Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@ -254,23 +253,6 @@
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
06400C234E158CC19ED60959 /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
|
||||
);
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputFileListPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
3399D490228B24CF009A79C7 /* ShellScript */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
|
@ -29,20 +29,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
chewie:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: chewie
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
chewie_audio:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: chewie_audio
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -78,13 +64,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
ffi:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: ffi
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@ -97,27 +76,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.0"
|
||||
flutter_html:
|
||||
flutter_inappwebview:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_html
|
||||
name: flutter_inappwebview
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
flutter_layout_grid:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_layout_grid
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
flutter_math_fork:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_math_fork
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.3"
|
||||
version: "5.3.2"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -125,13 +90,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
flutter_svg:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_svg
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.22.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@ -142,6 +100,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_widget_from_html_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_widget_from_html_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.1+1"
|
||||
html:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -212,13 +177,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -226,20 +184,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
path_drawing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_drawing
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.1"
|
||||
path_parsing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_parsing
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.1"
|
||||
pedantic:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -261,20 +205,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
provider:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.0.0"
|
||||
quiver:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: quiver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
rich_editor:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -329,13 +259,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: tuple
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -350,76 +273,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
video_player:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: video_player
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
video_player_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: video_player_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.1.0"
|
||||
video_player_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: video_player_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
wakelock:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.2"
|
||||
wakelock_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_macos
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.0+1"
|
||||
wakelock_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.1+1"
|
||||
wakelock_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.0+1"
|
||||
wakelock_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.0"
|
||||
webview_flutter:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: webview_flutter
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.7"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: win32
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -435,5 +288,5 @@ packages:
|
||||
source: hosted
|
||||
version: "5.2.0"
|
||||
sdks:
|
||||
dart: ">=2.13.0 <3.0.0"
|
||||
dart: ">=2.12.0 <3.0.0"
|
||||
flutter: ">=2.0.0"
|
||||
|
@ -1 +1,2 @@
|
||||
/// Position the inbuilt Toolbar or use your custom toolbar
|
||||
enum BarPosition { TOP, BOTTOM, CUSTOM }
|
@ -4,12 +4,13 @@ import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:rich_editor/src/models/enum/bar_position.dart';
|
||||
import 'package:rich_editor/src/models/rich_editor_options.dart';
|
||||
import 'package:rich_editor/src/services/local_server.dart';
|
||||
import 'package:rich_editor/src/utils/javascript_executor_base.dart';
|
||||
import 'package:rich_editor/src/widgets/editor_tool_bar.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
// import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class RichEditor extends StatefulWidget {
|
||||
final String? value;
|
||||
@ -30,10 +31,12 @@ class RichEditor extends StatefulWidget {
|
||||
}
|
||||
|
||||
class RichEditorState extends State<RichEditor> {
|
||||
WebViewController? _controller;
|
||||
InAppWebViewController? _controller;
|
||||
final Key _mapKey = UniqueKey();
|
||||
String assetPath = 'packages/rich_editor/assets/editor/editor.html';
|
||||
|
||||
// InAppWebViewController? webViewController;
|
||||
|
||||
int port = 5321;
|
||||
String html = '';
|
||||
LocalServer? localServer;
|
||||
@ -42,8 +45,7 @@ class RichEditorState extends State<RichEditor> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
||||
if (!Platform.isAndroid) {
|
||||
if (Platform.isIOS) {
|
||||
_initServer();
|
||||
}
|
||||
}
|
||||
@ -76,7 +78,11 @@ class RichEditorState extends State<RichEditor> {
|
||||
|
||||
_loadHtmlFromAssets() async {
|
||||
final filePath = assetPath;
|
||||
_controller!.loadUrl("http://localhost:$port/$filePath");
|
||||
_controller!.loadUrl(
|
||||
urlRequest: URLRequest(
|
||||
url: Uri.tryParse('http://localhost:$port/$filePath'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -86,42 +92,50 @@ class RichEditorState extends State<RichEditor> {
|
||||
Visibility(
|
||||
visible: widget.editorOptions!.barPosition == BarPosition.TOP,
|
||||
child: EditorToolBar(
|
||||
controller: _controller,
|
||||
getImageUrl: widget.getImageUrl,
|
||||
javascriptExecutor: javascriptExecutor,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: WebView(
|
||||
child: InAppWebView(
|
||||
key: _mapKey,
|
||||
onWebViewCreated: (WebViewController controller) async {
|
||||
onWebViewCreated: (controller) async {
|
||||
_controller = controller;
|
||||
setState(() {});
|
||||
if (!Platform.isAndroid) {
|
||||
await _loadHtmlFromAssets();
|
||||
} else {
|
||||
await _controller!
|
||||
.loadUrl('file:///android_asset/flutter_assets/$assetPath');
|
||||
await _controller!.loadUrl(
|
||||
urlRequest: URLRequest(
|
||||
url: Uri.tryParse(
|
||||
'file:///android_asset/flutter_assets/$assetPath'),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
onLoadStop: (controller, link) async {
|
||||
javascriptExecutor.init(_controller!);
|
||||
},
|
||||
onPageFinished: (link) async {
|
||||
await _setInitialValues();
|
||||
_addJSListener();
|
||||
},
|
||||
javascriptMode: JavascriptMode.unrestricted,
|
||||
gestureNavigationEnabled: true,
|
||||
// javascriptMode: JavascriptMode.unrestricted,
|
||||
// gestureNavigationEnabled: false,
|
||||
gestureRecognizers: [
|
||||
Factory(() => VerticalDragGestureRecognizer()..onUpdate = (_) {}),
|
||||
].toSet(),
|
||||
onWebResourceError: (e) {
|
||||
print("error ${e.description}");
|
||||
onLoadError: (controller, url, code, e) {
|
||||
print("error $e $code");
|
||||
},
|
||||
onConsoleMessage: (controller, consoleMessage) async {
|
||||
print(
|
||||
'WebView Message: $consoleMessage',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: widget.editorOptions!.barPosition == BarPosition.BOTTOM,
|
||||
child: EditorToolBar(
|
||||
controller: _controller,
|
||||
getImageUrl: widget.getImageUrl,
|
||||
javascriptExecutor: javascriptExecutor,
|
||||
),
|
||||
@ -148,6 +162,14 @@ class RichEditorState extends State<RichEditor> {
|
||||
.setBaseFontFamily(widget.editorOptions!.baseFontFamily!);
|
||||
}
|
||||
|
||||
_addJSListener() async {
|
||||
_controller!.addJavaScriptHandler(
|
||||
handlerName: 'editor-state-changed-callback://',
|
||||
callback: (c) {
|
||||
print('Callback $c');
|
||||
});
|
||||
}
|
||||
|
||||
/// Get current HTML from editor
|
||||
Future<String?> getHtml() async {
|
||||
try {
|
||||
@ -170,7 +192,7 @@ class RichEditorState extends State<RichEditor> {
|
||||
/// Clear editor content using Javascript
|
||||
clear() {
|
||||
_controller!.evaluateJavascript(
|
||||
'document.getElementById(\'editor\').innerHTML = "";');
|
||||
source: 'document.getElementById(\'editor\').innerHTML = "";');
|
||||
}
|
||||
|
||||
/// Focus and Show the keyboard using JavaScript
|
||||
@ -192,7 +214,7 @@ class RichEditorState extends State<RichEditor> {
|
||||
" link.media = \"all\";" +
|
||||
" head.appendChild(link);" +
|
||||
"}) ();";
|
||||
_controller!.evaluateJavascript(jsCSSImport);
|
||||
_controller!.evaluateJavascript(source: jsCSSImport);
|
||||
}
|
||||
|
||||
/// if html is equal to html RichTextEditor sets by default at start
|
||||
|
@ -1,16 +1,16 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:rich_editor/src/extensions/extensions.dart';
|
||||
import 'package:rich_editor/src/models/editor_state.dart';
|
||||
import 'package:rich_editor/src/models/enum/command_name.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
import '../models/command_state.dart';
|
||||
|
||||
/// A class that handles all editor-related javascript functions
|
||||
class JavascriptExecutorBase {
|
||||
WebViewController? _controller;
|
||||
InAppWebViewController? _controller;
|
||||
|
||||
String defaultHtml = "<p>\u200B</p>";
|
||||
|
||||
@ -22,12 +22,12 @@ class JavascriptExecutorBase {
|
||||
var didHtmlChange = false;
|
||||
Map<CommandName, CommandState> commandStates = {};
|
||||
|
||||
init(WebViewController controller) {
|
||||
init(InAppWebViewController? controller) {
|
||||
_controller = controller;
|
||||
}
|
||||
|
||||
executeJavascript(String command) async {
|
||||
return await _controller!.evaluateJavascript('editor.$command');
|
||||
return await _controller!.evaluateJavascript(source: 'editor.$command');
|
||||
}
|
||||
|
||||
String getCachedHtml() {
|
||||
|
@ -7,20 +7,17 @@ import 'package:rich_editor/src/widgets/fonts_dialog.dart';
|
||||
import 'package:rich_editor/src/widgets/insert_image_dialog.dart';
|
||||
import 'package:rich_editor/src/widgets/insert_link_dialog.dart';
|
||||
import 'package:rich_editor/src/widgets/tab_button.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
import 'color_picker_dialog.dart';
|
||||
import 'font_size_dialog.dart';
|
||||
import 'heading_dialog.dart';
|
||||
|
||||
class EditorToolBar extends StatelessWidget {
|
||||
final WebViewController? controller;
|
||||
final Function(File image)? getImageUrl;
|
||||
final Function(File video)? getVideoUrl;
|
||||
final JavascriptExecutorBase javascriptExecutor;
|
||||
|
||||
EditorToolBar({
|
||||
this.controller,
|
||||
this.getImageUrl,
|
||||
this.getVideoUrl,
|
||||
required this.javascriptExecutor,
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
|
||||
import 'html_text.dart';
|
||||
|
||||
class FontSizeDialog extends StatelessWidget {
|
||||
List formats = [
|
||||
@ -22,7 +23,7 @@ class FontSizeDialog extends StatelessWidget {
|
||||
children: [
|
||||
for (Map format in formats)
|
||||
InkWell(
|
||||
child: Html(data: format['title']),
|
||||
child: HtmlText(html: format['title']),
|
||||
onTap: () => Navigator.pop(context, format['id']),
|
||||
)
|
||||
],
|
||||
|
@ -1,9 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:rich_editor/src/models/system_font.dart';
|
||||
import 'package:rich_editor/src/utils/font_list_parser.dart';
|
||||
|
||||
import 'html_text.dart';
|
||||
|
||||
class FontsDialog extends StatelessWidget {
|
||||
List<SystemFont> getSystemFonts() {
|
||||
return FontListParser().getSystemFonts();
|
||||
@ -19,8 +20,8 @@ class FontsDialog extends StatelessWidget {
|
||||
children: [
|
||||
for (SystemFont font in getSystemFonts())
|
||||
InkWell(
|
||||
child: Html(
|
||||
data: '<p style="font-family:${font.name}">'
|
||||
child: HtmlText(
|
||||
html: '<p style="font-family:${font.name}">'
|
||||
'${basename(font.path!)}</p>'),
|
||||
onTap: () {
|
||||
Navigator.pop(context, font.name);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
|
||||
import 'html_text.dart';
|
||||
|
||||
class HeadingDialog extends StatelessWidget {
|
||||
List formats = [
|
||||
@ -27,7 +28,7 @@ class HeadingDialog extends StatelessWidget {
|
||||
children: [
|
||||
for (Map format in formats)
|
||||
InkWell(
|
||||
child: Html(data: format['title']),
|
||||
child: HtmlText(html: format['title']),
|
||||
onTap: () => Navigator.pop(context, format['id']),
|
||||
)
|
||||
],
|
||||
|
13
lib/src/widgets/html_text.dart
Normal file
13
lib/src/widgets/html_text.dart
Normal file
@ -0,0 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
|
||||
|
||||
class HtmlText extends StatelessWidget {
|
||||
final String html;
|
||||
|
||||
HtmlText({required this.html});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(child: HtmlWidget(html), height: 40.0,);
|
||||
}
|
||||
}
|
176
pubspec.lock
176
pubspec.lock
@ -29,20 +29,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
chewie:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: chewie
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
chewie_audio:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: chewie_audio
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -64,13 +50,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.17.0"
|
||||
cupertino_icons:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: cupertino_icons
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -78,13 +57,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
ffi:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: ffi
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@ -97,27 +69,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.0"
|
||||
flutter_html:
|
||||
flutter_inappwebview:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_html
|
||||
name: flutter_inappwebview
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
flutter_layout_grid:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_layout_grid
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
flutter_math_fork:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_math_fork
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.3"
|
||||
version: "5.3.2"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -125,13 +83,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
flutter_svg:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_svg
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.22.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@ -142,6 +93,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_widget_from_html_core:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_widget_from_html_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.1+1"
|
||||
html:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -212,13 +170,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
path:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -226,20 +177,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
path_drawing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_drawing
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.1"
|
||||
path_parsing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_parsing
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.1"
|
||||
pedantic:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -261,20 +198,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
provider:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.0.0"
|
||||
quiver:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: quiver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@ -322,13 +245,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: tuple
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -343,76 +259,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
video_player:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: video_player
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
video_player_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: video_player_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.1.0"
|
||||
video_player_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: video_player_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
wakelock:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.2"
|
||||
wakelock_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_macos
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.0+1"
|
||||
wakelock_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.1+1"
|
||||
wakelock_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.0+1"
|
||||
wakelock_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.0"
|
||||
webview_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: webview_flutter
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.7"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: win32
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -428,5 +274,5 @@ packages:
|
||||
source: hosted
|
||||
version: "5.2.0"
|
||||
sdks:
|
||||
dart: ">=2.13.0 <3.0.0"
|
||||
dart: ">=2.12.0 <3.0.0"
|
||||
flutter: ">=2.0.0"
|
||||
|
@ -10,10 +10,10 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
webview_flutter: ^2.0.4
|
||||
flutter_inappwebview: ^5.3.2
|
||||
mime: ^1.0.0
|
||||
image_picker: ^0.7.5+3
|
||||
flutter_html: ^2.0.0
|
||||
flutter_widget_from_html_core: ^0.6.1+1
|
||||
flutter_colorpicker: ^0.4.0
|
||||
path: ^1.8.0
|
||||
xml2json: ^5.2.0
|
||||
|
Loading…
Reference in New Issue
Block a user