smaranjitghose / DocLense

An open-source document scanner!
https://doclense.vercel.app/
Creative Commons Zero v1.0 Universal
147 stars 130 forks source link

Bug: Storing 'File' type in Hive Box and the disappearing PDFs #242

Closed Saransh-cpp closed 3 years ago

Saransh-cpp commented 3 years ago

Bugs

  1. After a PDF is created or after the PDF is starred, the console throws this error which actually does not affect anything but should be fixed.
E/flutter (10565): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: HiveError: Cannot write, unknown type: _File. Did you forget to register an adapter?
E/flutter (10565): #0      BinaryWriterImpl.write (package:hive/src/binary/binary_writer_impl.dart:310:9)
E/flutter (10565): #1      BinaryWriterImpl.writeList (package:hive/src/binary/binary_writer_impl.dart:204:7)
E/flutter (10565): #2      BinaryWriterImpl._writeList (package:hive/src/binary/binary_writer_impl.dart:362:7)
E/flutter (10565): #3      BinaryWriterImpl.write (package:hive/src/binary/binary_writer_impl.dart:301:7)
E/flutter (10565): #4      BinaryWriterImpl.writeList (package:hive/src/binary/binary_writer_impl.dart:204:7)
E/flutter (10565): #5      BinaryWriterImpl._writeList (package:hive/src/binary/binary_writer_impl.dart:362:7)
E/flutter (10565): #6      BinaryWriterImpl.write (package:hive/src/binary/binary_writer_impl.dart:301:7)
E/flutter (10565): #7      BinaryWriterImpl.writeFrame (package:hive/src/binary/binary_writer_impl.dart:254:9)
E/flutter (10565): #8      StorageBackendVm.writeFrames.<anonymous closure> (package:hive/src/backend/vm/storage_backend_vm.dart:123:31)
E/flutter (10565): #9      StorageBackendVm.writeFrames.<anonymous closure> (package:hive/src/backend/vm/storage_backend_vm.dart:119:28)
E/flutter (10565): #10     ReadWriteSync.syncWrite.<anonymous closure> (package:hive/src/backend/vm/read_write_sync.dart:26:41)
E/flutter (10565): #11     _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (10565): #12     _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (10565): #13     _FutureListener.handleValue (dart:async/future_impl.dart:152:18)
E/flutter (10565): #14     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:704:45)
E/flutter (10565): #15     Future._propagateToListeners (dart:async/future_impl.dart:733:32)
E/flutter (10565): #16     Future._addListener.<anonymous closure> (dart:async/future_impl.dart:403:9)
E/flutter (10565): #17     _rootRun (dart:async/zone.dart:1354:13)
E/flutter (10565): #18     _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (10565): #19     _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (10565): #20     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
E/flutter (10565): #21     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (10565): #22     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (10565):
  1. Whenever the app is closed and opened again, the PDFs somehow disappear. They are available on the location in which they were stored in the device but are not available through the app. My initial guess is that the above error is creating this bug so now it becomes more important to fix it.

Solution

I am thinking of converting the images to strings and then storing them in the Hive box as the 'File' data type is the one giving us this error.

I will work on this and make a PR whenever I fix this.

anushbhatia commented 3 years ago

Yes, we can store the images into strings rather than that can we store the file paths present there to the hive box and retrieve them directly in the app.

File file = await // get the document here

final path = file.path

var box = await Hive.openBox('doc');

var m = doc()
  ..name = 'Name of pdf'
  ..path = path ;
box.add(m);

m.save();

Hope this medium article helps.

Saransh-cpp commented 3 years ago

Yes, we can store the images into strings rather than that can we store the file paths present there to the hive box and retrieve them directly in the app.

File file = await // get the document here

final path = file.path

var box = await Hive.openBox('doc');

var m = doc()
  ..name = 'Name of pdf'
  ..path = path ;
box.add(m);

m.save();

Hope this medium article helps.

Thanks! I will look into this