Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : Value #4

Closed
angwandi opened this issue Jan 11, 2021 · 14 comments
Closed

Question : Value #4

angwandi opened this issue Jan 11, 2021 · 14 comments

Comments

@angwandi
Copy link

angwandi commented Jan 11, 2021

What's the best way to get the exact value from QuillEditor then save to firebase or something?

And also, how to display the exact value back from Firebase or some sort of backend?

I am using _controller.document.toPlainText(); and saving only simple string

@singerdmx
Copy link
Owner

What do you mean by the exact value from QuillEditor ?
You can get delta of the document.

@angwandi
Copy link
Author

angwandi commented Jan 12, 2021

@singerdmx I used this _controller.document.toDelta().toString(); to only get :

"insert⟨ Thanks for the invite and I ⟩ insert⟨ ⏎ ⟩ + {indent: 1} insert⟨ Thank u for ⟩ insert⟨ ⏎ ⟩ + {indent: 1, list: ordered} insert⟨ Best friend ⟩ insert⟨ ⏎ ⟩ + {indent: 1, list: ordered} insert⟨ Thanks for the invite and I appreciate it and I appreciate it and ⟩ insert⟨ ⏎⏎ ⟩ + {indent: 1}"

Trying to display the above from Firestore and I get this :

quill2

I tought it will be saved looking exactly like this :

quill

@levy0601
Copy link
Collaborator

@angwandi

  1. If you want to store the plain text (which mean it will lose all the format info like list, code block and link), you can use _controller.document.toPlainText()
  2. This library use quill_delta as an internal data type to store all the formatting information as well as the text. Therefore, what you see from the _controller.document.toDelta().toString(); is the representation of the Delta data type. If you want to store the get the exact value from QuillEditor, you should use _controller.document.toDelta().toJson(). Noted that you will need to use an additional library to show the exact format from Detla to see what you see in the screenshot.

check out https://quilljs.com/docs/delta/ playground section for more information

@angwandi
Copy link
Author

@levy0601 thank you so much. any suggestions for library to display in flutter?

@levy0601
Copy link
Collaborator

levy0601 commented Jan 14, 2021

@angwandi

Noted that you will need to use an additional library to show the exact format from Detla to see what you see in the screenshot.

What I mean by the additional library is to show the delta in the web browser

If you are talking about display it in Flutter, you can just use our library.

check the following example for display a delta in flutter-quill;

@override
void initState() {
      Document _document =Document.fromJson( delta );
      QuillController _controller = QuillController(
                  document: _document, selection: TextSelection.collapsed(offset: 0));
}
@override
  Widget build(BuildContext context) {
      return QuillEditor.basic(
                  controller: _controller,
                  readOnly: true,
                )
}

you can also set the QuillEditor as ReadOnly view by passing in readOnly: true,

@angwandi
Copy link
Author

@levy0601 thank you. let me give it a go.

@singerdmx
Copy link
Owner

@angwandi let us know if you have any issue. We are happy to resolve it for you.

@angwandi
Copy link
Author

angwandi commented Jan 14, 2021

@singerdmx

E/flutter (10374): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Invalid argument: Instance of 'Operation' E/flutter (10374): #0 convertPlatformException (package:cloud_firestore_platform_interface/src/method_channel/utils/exception.dart:13:5) E/flutter (10374): #1 MethodChannelDocumentReference.set (package:cloud_firestore_platform_interface/src/method_channel/method_channel_document_reference.dart:43:13) E/flutter (10374): <asynchronous suspension> E/flutter (10374): #2 CollectionReference.add (package:cloud_firestore/src/collection_reference.dart:45:5) E/flutter (10374): <asynchronous suspension>

getting this error when trying to save on Firestore using :
data[AppEventFields.longDescription] = _longDescriptionQuillController.document.toDelta().toJson();

data[AppEventFields.longDescription] = _longDescriptionQuillController.document.toDelta() works fine and also data[AppEventFields.longDescription] = _longDescriptionQuillController.document.toPlainText(); works fine

@singerdmx
Copy link
Owner

This seems more of Filestore issue, which we are unfamiliar with

@WingCH
Copy link

WingCH commented Mar 7, 2021

in example sample_data.json
image

when i call _controller.document.toDelta().toJson()

image

How can I get the same format as sample_data.json?

@singerdmx
Copy link
Owner

This is more of a question how to prettify json string. You can check out https://pub.dev/packages/pretty_json
Those questions are not related to flutter-quill and please DO NOT ask those here.

@WingCH
Copy link

WingCH commented Mar 7, 2021

thanks for your quick reply.

I think I understand the real problem with @angwandi
we need usejsonEncode to convert Delta to json format and then save to firebase

String jsonString = jsonEncode(_controller.document.toDelta().toJson());

image

@ArjanAswal
Copy link
Collaborator

ArjanAswal commented Mar 7, 2021

This is more of a question how to prettify json string. You can check out https://pub.dev/packages/pretty_json
Those questions are not related to flutter-quill and please DO NOT ask those here.

@singerdmx I think we should pin the firebase issue as it is pretty common.
Also I think we should create an issue template so that people don't ask unrelated questions.

@singerdmx
Copy link
Owner

image

This is already in README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants