Thanks, very well made tutorial and useful. I was considering to switch to Hive earlier already for storing app settings. After this I am convinced and with a good and easy to follow guide.
I started today with hive...at the beginning hard to unterstand things like typeadapter and so..i fumbeld round about 2 hours with generating of the .g.dart File..because Null Safety Problems from Others dependencies..but now hive is very fast and very nice to handle, Not Like sqlite3 or so. Thank you for this tutorial which i found just a hour later after i solved much of the shown ways alone or by Stack Overflow 🤣
Great tutorial. And the same for the others on your channel. Keep up the great work, yours is definitely a really good channel to learn Flutter and various libraries!
I solved that analyzer stuff by just using pubspec assist and providing analyzer package that was 2 versions down. That way, when the issue is fixed all i need to do is make the package version empty then run pub upgrade
Basic question: What would be the difference if instead of using: > final contact = contactsBox.get(index) as Contact; I used this: > Contact contact = contactsBox.get(index);
Great walk through of Hive, but outdated. Lots of updates in current version 2.0.4 not covered in your tutorial. Would be great to see an updated version. E.g. typeId is required to generate type adapter now and when registering an adapter, typeId cannot be passed as shown in video. I'm sure it's a pain to stay current with updates on packages. Problem is you make tutorials that are too good so we expect you'll keep them current with every minor version update of any package. :)
The build runner failed until I modified the @HiveType annotation to read @HiveType(typeId:0). I am using build_runner version ^1.11.1. I am really enjoying this process. Thanks.
Nice tutorial and thanks for clarifying some stuff for me. On the build _runner/Dart analyzer thing. I shared the same experience but while creating a generator/build library. I almost went mad.
Getting issues with typeId, had to add typeId to the generator and remove from registerAdapter, eg: Hive.registerAdapter(ContactAdapter()); @HiveType(typeId: 0) using hive: ^1.3.0, hive_flutter^0.3.0+1, hive_generator: ^0.7.0
How can we make sure that the application doesn't load data from firestore every time it starts ? Only fetch when some changes is done in the database.
Does anyone else have issues with the part file not being created after running the build runner? :( It is building successfully for me but I don't get a part file.. Edit: figured it out, the part name needs to match your file name, not the class name.
Compact is a deep english word, it couldve been better if you shown an animation of how it works under the hood(like showing a real world example). I really did not understand seeing the `compactStrategy` and cant image how it works under the hood. However it is a good tutorial tho. I just do not get the use of the `compactStrategy`.
Hello Ahmed from Egypt I enjoyed a lot of explanation of flutter I would like you to help me think I started creating an app to create merchant accounts I will use an internal database I would collect a column and use the sum again Do I use sqflite with flutter Or use a package from no sql database packages
i got the problem for my error void main() async{ WidgetsFlutterBinding.ensureInitialized(); var appDocumentDir = await path_provider.getApplicationDocumentsDirectory(); Hive.init(appDocumentDir.path); runApp(MyApp()); } add this WidgetsFlutterBinding.ensureInitialized(); before you get the path
Superb. Matej, I have somewhat of an unrelated question to Hive. It occurred after you used compact() inside of dispose override. I guess compact() is a sync method. However for the sake of argument, what if it was an async method. Can we use an async call inside of dispose()? I could not find any info on SO. Thanks man.
For those who get this error for build_runner: [INFO] Generating build script... [INFO] Generating build script completed, took 613ms [INFO] Creating build script snapshot...... [INFO] Creating build script snapshot... completed, took 25.4s [INFO] Initializing inputs [INFO] Building new asset graph... [INFO] Building new asset graph completed, took 1.3s [INFO] Checking for unexpected pre-existing outputs.... [INFO] Checking for unexpected pre-existing outputs. completed, took 3ms [INFO] Running build... [INFO] 1.1s elapsed, 9/10 actions completed. [INFO] 4.3s elapsed, 9/10 actions completed. [SEVERE] hive_generator:hive_generator on lib/modals/contact.dart: You have to provide a non-null typeId.
I'm having the same problem here. I'm a beginner in flutter, I'm wondering why it is still error, I already follow about what should be the remedy. If I remove the carat notation and type flutter clean, and flutter pub get or just flutter pub get, it gives me this error. Because every version of flutter_test from sdk depends on path 1.8.0-nullsafety and hive >=0.4.1 =1.6.0 =0.4.1
Does Hive.openbox('contacts') will not be called every time build() is called? The doc (api.flutter.dev/flutter/widgets/FutureBuilder-class.html) says: "If the future is created at the same time as the FutureBuilder, then every time the FutureBuilder's parent is rebuilt, the asynchronous task will be restarted."
I m getting 'type 'String' is not a subtype of type 'Contact' in type cast' error on this line 'final contact = contactsBox.get(index) as Contact;' Thank you
Hey my question is do I need to ask for permission from user something like internal storage permission etc, or I can simply use it without permission as it is and in what file format it stores your data and where 🙄🙄 please help me out
After adding items to my box and reopening the app, im getting an error: Unhandled Exception: RangeError: Not enough bytes available. I can't find a proper solution for this. Anyone know's what to do?
Just in case someone else is stuck at the same point as me where he talks about the WatchBoxBuilder. Down below in the comments is the solution which I modified a little: Widget _buildListView() { final contactsBox = Hive.box('contacts'); return ValueListenableBuilder( valueListenable: Hive.box('contacts').listenable(), builder: (context, contactsBox, _) { return ListView.builder( itemCount: contactsBox.length, itemBuilder: (context, index) { final contact = contactsBox.getAt(index) as Contact; return ListTile( title: Text(contact.name), subtitle: Text(contact.age.toString()), ); }, ); }, ); } }
when you use clean architecture the entities will get polluted with these annotations. It looks terrible and at the end entities will depend on these annotations.
Hi @Reso Coder, What line identation guide extension do you use (the highlighted lines of method/ properties)? E.g: Scaffold has highlighted lines for appBar and body and their childs. I've searched through vscode extensions but couldn't find it.
Every write operation is actually async. You just don't have to await them. By default the contents of a box are cached so read operations don't access the disk. If you don't want the values to be cached, you can use "Lazy Boxes" which have async get, getAt etc.