How to store data (paragraphs) in the text editor app in a flutter. Text editor was built with Quill package. do I need to fetch external APIs or any other package or storage is already available in the Quill package in flutter and also if that api or storage package provide cloud storage or local storage i users phone storage
CodePudding user response:
Convert the content to a json string
var json = jsonEncode(_controller.document.toDelta().toJson());
Use a package named shared preferences
Save the json string using shared preferences.
To retrieve data use
var myJSON = jsonDecode(incomingJSONText);
_controller = QuillController(
document: Document.fromJson(myJSON),
selection: TextSelection.collapsed(offset: 0));
Check https://github.com/singerdmx/flutter-quill for more info
CodePudding user response:
If you want the data to be stored online,, you may use firebase, or any online db like mySql, MongoDB and many many other options
however,, If you want to store them locally on the phone, without using the internet, and have these data to be persistent, "kill app then rerun and find that data in a new session",, then you need to use a local db,, like sqfLite or Sembast Flutter packages,,
Sembast is super fast and easy noSQL local db.. while sqfLite is an SQL db
and if you just need to store the data while the session is going ,, and to be disposed when app is killed,, you may store the data in a global variable using bloc or provider in a class that extends ChangeNotifier
and if you just want to store the data in the current active screen and dispose the data when closing the screen,, just set a local variable with that data in a statefulWidget's state class..