Stephen S
Stephen S

Reputation: 165

Flutter: best way to save large data amounts

My app allows users to create templates and draft documents. Each document/ template is an instance of a class which itself consists of some Strings and a List of sections. Sections also consist of strings, DateTime class objects and can include a File representing an image taken from a user's photos or a user generated sketch. There is currently no limit on the size of a document/ template (if I put one in it will be as large as possible) or the number of documents/ templates and I anticipate that some users may have fairly large amounts of data.

I need to store this data on the device as the user creates it so that it can be retrieved in new sessions. For premium users I will also allow them to back the data up off device (using Firebase) so that it can be retrieved from multiple devices and in case the main device is lost or damaged etc.

My question is the best way to store that data and how to do that. Flutter offers Preferences, Text Files and SQLite while Firebase cloud storage seems to offer the ability to store JSON documents.

A document has the following structure:

DocDraft newDraft = new DocDraft(
    type: String,
    name: String,
    content: List<Section>,
    dateCreated: DateTime,
    dateEdited: DateTime,
  );

and the Section class is as follows:

  Section(
      sType: String,
      sLabel: String,
      sText: String,
      sFile: File,);

Templates are similar to Documents but simpler as they don't have DateTimes or Files.

Both Documents and Templates are currently stored in Lists within my app.

Any advice on the best way to store/ retrieve such data within the app and across to Firebase would be much appreciated as would any guidance on how to do this.

Thanks for your help.

Upvotes: 0

Views: 2055

Answers (2)

MUCHIRA JUNIOR
MUCHIRA JUNIOR

Reputation: 127

Using file storage.

You can try path provider package or use inbuilt root bundle in Flutter and save the data like in JSON strings or objects

Upvotes: 0

Code on the Rocks
Code on the Rocks

Reputation: 17614

Use the Hive package. Pros:

  • Written in Dart
  • Lots of good documentation
  • Easy to set up
  • Supports storing custom objects using HiveAdapters
  • Fast

Upvotes: 3

Related Questions