Create and load an HTML file with the Quill editor and Codox initialization logic using a WebView.
In Flutter, fetch the initial document state from the backend and initialize the Quill editor.
In Flutter, set up listeners (callbacks) to respond to Codox client library session and error events.
Explicitly start Codox session via a javascript interface.
When Codox triggers hooks in the JavaScript code, corresponding callbacks in Flutter are invoked, passing the necessary data.
Step-by-Step Integration Tutorial
Step 1: Set Up Local Files
The first step is to prepare the local files for your project. Create a directory named assets/ in the root of your Flutter project to store HTML and JavaScript files.
Navigate to the assets/ directory and create an HTML file:
Create a directory for Codox library files:
Navigate to the codoxLib/ directory and create a package.json file:
Install the library:
Copy the Codox library to the assets/ directory:
The assets/ directory should now look like this:
Step 2: Initialize QuillJS Editor
Add the following code to quill.html to set up the Quill editor:
Step 3: Initialize InAppWebView in Flutter
To display the HTML/Javascript app in Flutter, we will use the InAppWebView plugin. The following code in lib/main.dart sets this up:
Step 4: Initialize the Editor State
Before starting or joining a Codox session, the latest version of the document content must be available to the QuillJS editor component. The following code shows one way to set up this up from the Flutter app.
Add an initialization function in your HTML/Javascript quill.html to expose a method for Flutter to set up the editor with initial content.
Then, invoke this function from Flutter after the page has been fully loaded using the onLoadStop callback from InAppWebView .
Start Codox Session
To start or joining a Codox session, you need to explicitly call codox.start to connect to the session.
Setup start session code in quill.html:
Then, invoke this function from Flutter after the page has been fully loaded using the onLoadStop callback from InAppWebView, in lib/main.dart . Note that starting the session proceeds after the initial document state has been passed into the editor.
Optional: Codox Hooks and Error events
You can listen to events from Codox to allow the Flutter app to respond to content change notifications, member change notifications, and errors triggered within the Codox session.
In quill.html, define callback functions and include them in the config object passed to Codox. These callbacks are triggered internally when specific events occur and serve as bridges to invoke corresponding handlers in the Flutter app.
On the Flutter side you need to setup handlers to manage JavaScript messages sent from Codox, like the following example in lib/main.dart: