Hive (Flutter Tutorial) - Lightweight & Fast NoSQL Database in Pure Dart

Поділитися
Вставка
  • Опубліковано 10 лип 2024
  • 📗 Get the starter project & learn from the written tutorial 👇👇
    resocoder.com/hive-db-tutorial
    👨‍💻 Do you write good code? Find out now!
    resocoder.com/good-code-quiz
    Storing data locally is a task which has to be done by almost every app. Maybe, you want to cache responses from a REST API or you're building an offline-only app. In any case, choosing the right local database can make all the difference in how quickly you can develop the app and also in how performant the app will be.
    Hive is a lightweight, yet powerful database which is easy to develop with and it also runs fast on the device. Unless you absolutely need to model your data with many relationships, in which case you should probably use SQLite, choosing this pure-Dart package with no native dependencies (it runs on Flutter Web!) can be the best option.
    Go to my website for more information, code examples, and articles:
    ● resocoder.com
    Follow me on social media:
    ● / resocoder
    ● / resocoder
    ● / resocoder

КОМЕНТАРІ • 174

  • @Hypothermia1337
    @Hypothermia1337 3 роки тому +4

    Most underrated flutter-tutor on youtube! Love your work, it's keeping us folks on coding with flutter! Props to you mate!

  • @BrendansReasons
    @BrendansReasons 2 роки тому +2

    You're really important to the community, Reso! Thanks!

  • @FilledStacks
    @FilledStacks 4 роки тому +78

    Awesome. Hive looks like a much more viable option than SQLite to me in terms of simplicity and ease of setup and use. Thanks for the tutorial.

    • @rossthemusicandguitarteacher
      @rossthemusicandguitarteacher 4 роки тому +10

      The two best coding channels for me at the moment. Much love and thanks for all the help.

    • @FilledStacks
      @FilledStacks 4 роки тому +9

      @@rossthemusicandguitarteacher Thanks Ross! I love myself some ResoCoder too :)

  • @ManOnTheMoon2131
    @ManOnTheMoon2131 3 роки тому

    This was incredibly helpful. Thank you! Subscribed!

  • @simonleier502
    @simonleier502 4 роки тому +58

    Great video and very well written tutorial. Good job! I added your video to the documentation.

    • @ResoCoder
      @ResoCoder  4 роки тому +6

      Thanks for the library again, Simon!

    • @rebarius
      @rebarius 4 роки тому +7

      @Simon Leier oh yes wanna thank you also sooo much for thie great package 👏🏼 Greatest feature for me is the possibility to save whole dart objects :)

    • @HarshSingh-hk8fe
      @HarshSingh-hk8fe 3 роки тому

      hi sir, can i store my shopping app cart list in hive thank you :D

  • @AshishGupta16
    @AshishGupta16 4 роки тому

    best hive video out there!! thanks :)

  • @fununterhaltung6556
    @fununterhaltung6556 3 роки тому +1

    Thank you very much for this wonderful tutorial!!

  • @mostafafahimi4588
    @mostafafahimi4588 3 роки тому

    Every second of this video was useful for me. Thanks.

  • @chetan6406
    @chetan6406 4 роки тому +1

    Best channels for learning flutter....thankyou

  • @leotrantruc
    @leotrantruc 4 роки тому

    Great video! Thank you so much.

  • @danieldey
    @danieldey 3 роки тому +2

    Very helpful video, much better then documentations for doing it first time.

  • @4funrc11
    @4funrc11 4 роки тому

    WOW! Impressed... Thx!

  • @ShitIndie
    @ShitIndie 4 роки тому +3

    I was going full inception, listening to The Hives while working with the Hive.

  • @theflutterboi
    @theflutterboi 3 роки тому

    Thank you so much for the tutorial 💙.

  • @wSRV
    @wSRV 4 роки тому +4

    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!

  • @MindzGroupTech
    @MindzGroupTech 4 роки тому

    Ok you got my subscription ... You are being so awesome

  • @mustafashaikh7829
    @mustafashaikh7829 4 роки тому +1

    Love your content Sir.....

  • @brianmanuputty4412
    @brianmanuputty4412 4 роки тому

    very useful, thank you

  • @rydmike
    @rydmike 4 роки тому +5

    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.

    • @ResoCoder
      @ResoCoder  4 роки тому +2

      I'm glad you found this useful, Mike!

  • @etiennetheodore
    @etiennetheodore 4 роки тому

    Thanks like always.

  • @SkShofiul
    @SkShofiul 4 роки тому

    finally new lightweight database !

  • @oblakus
    @oblakus 4 роки тому

    Great tutorial 👍

  • @himanshudhakecha1789
    @himanshudhakecha1789 3 роки тому

    helpful, Thanks for sharing

  • @yemenpoint_com
    @yemenpoint_com 4 роки тому

    Thanks boooy your the best

  • @nicolasdupere
    @nicolasdupere 4 роки тому

    You are so good.

  • @ajinata849
    @ajinata849 4 роки тому

    epic, this is epic.

  • @Klausi-uq4xq
    @Klausi-uq4xq 3 роки тому

    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 🤣

  • @gmc254quads6
    @gmc254quads6 4 роки тому

    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.

  • @MrHimanshun
    @MrHimanshun 3 роки тому

    Great tutorial, very clear and concise. I had question though, Is there a way to implement search with hive??

  • @burakbirer
    @burakbirer 3 роки тому +1

    Thank you. What do you think about Hive + Firestore implementation?

  • @Baraka0369
    @Baraka0369 4 роки тому

    Nice design dock and window btw ! What did u use ? Rainmeter ? And which package ?

  • @radurot7673
    @radurot7673 2 роки тому +1

    Great tutorial. Is there a flutter hive client/data visualiser to inspect boxes?

  • @gmc254quads6
    @gmc254quads6 4 роки тому +1

    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

  • @aytunch
    @aytunch 4 роки тому

    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.

  • @rtech8779
    @rtech8779 4 роки тому

    You are boss bro

  • @tahirdevlog2047
    @tahirdevlog2047 4 роки тому

    thankss

  • @easazade
    @easazade 4 роки тому

    hi, what kind of database do you use for your projects? hive? moor? etc? any recommendations?

  • @ahmadfarhat1014
    @ahmadfarhat1014 4 роки тому

    what vscode extension are you using to get tree-like parent-child , looks beautiful

  • @juanmanueljaramillohenao654
    @juanmanueljaramillohenao654 4 роки тому

    gracias papi

  • @PaulMcKillop
    @PaulMcKillop 3 роки тому +1

    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.

  • @ruslanssmolonskis9170
    @ruslanssmolonskis9170 4 роки тому

    Hello. I have a problem to find way how to make Flutter app which uses pre-populated database with some tables. Do you have any tutorial for that?

  • @pradeep422
    @pradeep422 4 роки тому

    lol I was just thinkin f this, Reso might upload today or tommorrow about Hive...

    • @ResoCoder
      @ResoCoder  4 роки тому +1

      I hope I didn't disappoint 😄

  • @tibebeselasiemehari7503
    @tibebeselasiemehari7503 4 роки тому +1

    Great content.. Thanks!
    One suggestion, @13:19 wouldn't returning "Center > CircularProgressIndicator" be better UX? than showing blank white screen

    • @ResoCoder
      @ResoCoder  4 роки тому +1

      Absolutely! There goes my UX prowess, I guess 😅

  • @LexPrimost
    @LexPrimost 4 роки тому +1

    Hey bro, hydrated_bloc or hive for ecommerce shopping cart for unregistred users? Thank you

  • @MoAdel92
    @MoAdel92 3 роки тому

    what is the vscode extension that tracing draw lines e.g between return and build?

  • @assoftpro
    @assoftpro 4 роки тому +1

    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

  • @gourav7315
    @gourav7315 4 роки тому

    Please make more Hive Flutter Video

  • @43_arshadsaiyed78
    @43_arshadsaiyed78 3 роки тому

    Which plugin you are using for brackets?

  • @wickedgummybear3104
    @wickedgummybear3104 4 роки тому

    Is it possible for you to update this? I'm trying to get this to work with the new Flutter version etc but it seems to keep crashing..

  • @oldmen2544
    @oldmen2544 3 роки тому

    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

  • @PaulMcKillop
    @PaulMcKillop 3 роки тому

    The build fails reporting that the abstract class ContactAdapter is missing implementation of members. Did I miss something?

  • @HarshSingh-hk8fe
    @HarshSingh-hk8fe 3 роки тому

    ​ @Reso Coder hi sir can i store my shopping app cart with hive ??

  • @kopianan
    @kopianan 4 роки тому

    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

  • @aminsamad6900
    @aminsamad6900 2 роки тому

    Does it support windows? And can I back up my data and load it on another platform?

  • @ZEEVLOGSzubair_malik
    @ZEEVLOGSzubair_malik Рік тому

    how i can get the same box value on other page but within same project

  • @rvng6
    @rvng6 3 роки тому

    Is it one key for one value ??
    I mean lets say i want to save a user data
    Means everytime new user i need new key or it will be overwrite ?

  • @armagan_gok
    @armagan_gok 2 роки тому

    where is the starter project link? please type it down I could not find it

  • @kartikshrivastava1500
    @kartikshrivastava1500 2 роки тому

    What is the search performance of hive? In case of millions of entries, is it suitable?

  • @gokulakrishnan1977
    @gokulakrishnan1977 4 роки тому

    Please tell me list if extension used by You.

  • @haviforg
    @haviforg 4 роки тому

    only local database or we can use it on server and how?

  • @usefulteam
    @usefulteam 4 роки тому

    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.

    • @scratchbfunk
      @scratchbfunk 4 роки тому +2

      It's actually part of the flutter/dart extension. just add "dart.previewFlutterUiGuides": true, to your settings!

  • @GabrielCosta-xr5vr
    @GabrielCosta-xr5vr 4 роки тому

    Is Hive better than Sembast? Sembast has queries so I was wondering if Hive can outperform Sembast even without queries for now..

  • @lainhathoang
    @lainhathoang 3 роки тому

    Can you give me the name of the theme u used for your vscode?

  • @LjaDj5XQKey9mSDxh4
    @LjaDj5XQKey9mSDxh4 3 роки тому +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."

  • @Hypothermia1337
    @Hypothermia1337 3 роки тому

    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?

  • @asp1re530
    @asp1re530 3 роки тому +2

    WatchBoxBuilder got depricated! Now its used ValueListenableBuilder.

  • @radouaneelayachi4878
    @radouaneelayachi4878 3 роки тому

    Is there anyway that you can do search in db with Hive ??
    there is No Where clause !!!!

  • @dan3f
    @dan3f 3 роки тому

    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);

  • @pradeepkumarreddykondreddy7048
    @pradeepkumarreddykondreddy7048 3 роки тому +1

    Where are we defining box name as contacts ?

  • @nathanzabaldo1054
    @nathanzabaldo1054 3 роки тому +2

    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. :)

  • @officialismailshah
    @officialismailshah 2 роки тому

    How can I add unique data in hive box

  • @rahulagarwal968
    @rahulagarwal968 4 роки тому +2

    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.

    • @EverisXD
      @EverisXD 3 роки тому

      wdym firestore lmao

  • @Sampelmind81
    @Sampelmind81 2 роки тому

    Is hive able to handle millions of items, is there a limit?

  • @kopianan
    @kopianan 4 роки тому

    i got error when get path in void main(). wht should i do ?

    • @imransefat8770
      @imransefat8770 4 роки тому +1

      WidgetsFlutterBinding.ensureInitialized();
      add this at the first line in main function

  • @marbenvillaflor6236
    @marbenvillaflor6236 3 роки тому

    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

  • @vinayp-20
    @vinayp-20 4 роки тому +2

    I might be asking a dumb question. Can Hive be used as a statemanagement as well? By creating different box

    • @oblakus
      @oblakus 4 роки тому +2

      Technically, yes. But provider is just as good, simple and optimized as it gets, so it's probably better solution

  • @bjorn6017
    @bjorn6017 4 роки тому

    are there any async methods to add or get data from hive? saving stuff on ui thread will probably freeze ui when data gets larger

    • @simonleier502
      @simonleier502 4 роки тому +3

      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.

  • @igorbondarenko9854
    @igorbondarenko9854 4 роки тому

    Thanks for your work, what about floor?

    • @ResoCoder
      @ResoCoder  4 роки тому +2

      I'd rather go with Moor if you want SQL.

  • @DKSTechnology
    @DKSTechnology 3 роки тому

    In Flutter can we create a copy of hive cluster as a backup 🙄

  • @haberinvarsa
    @haberinvarsa 2 роки тому

    Firebase set do hive ?

  • @adriano_souza
    @adriano_souza 3 роки тому

    How I implements this in TDD?

  • @nazar.kk1
    @nazar.kk1 3 роки тому

    May anybody tells me, why is it bad practice to expose offline data directly to the UI? 30:55 of the video

  • @billmellis7796
    @billmellis7796 4 роки тому

    What linux distro is that?

  • @ravichudgar
    @ravichudgar 4 роки тому

    can we give the primary key in hive ???

  • @armagan_gok
    @armagan_gok 2 роки тому +2

    it has been 2 years you should update codes!

  • @saicharansigiri2964
    @saicharansigiri2964 3 роки тому +4

    when you said "AUTOINCREMENT" at 18:00 when deleted a contact will it " AUTO DECREAMENT" i mean the KEY

    • @sagarv6246
      @sagarv6246 3 роки тому +1

      don't think so. That's now how Auto Increment works

  • @edhooksjr
    @edhooksjr 4 роки тому

    Matt, Is there a TypeAdapter solution for Android Studio? (i see pubspec assist is VS Code plugin) - Manual create TypeAdapter?

    • @edhooksjr
      @edhooksjr 4 роки тому

      Found it... Change #Lock file by Adding to pubspec.yaml dependency as any other package #analyzer: 0.38.2

    • @edhooksjr
      @edhooksjr 4 роки тому

      TypeGen still results this>[SEVERE] hive_generator:hive_generator on lib/models/contacts.dart:
      Error running TypeAdapterGenerator
      You have to provide a non-null typeId.

  • @bhanukaisuru2618
    @bhanukaisuru2618 4 роки тому +1

    omg...I completed your moor series. start project with moor. what is hive? what is the best one? please tell me

    • @Abion47
      @Abion47 4 роки тому +6

      Moor is a function package that is built on top of SQLite that makes it much easier to structure your app to integrate with a SQLite database. Hive, on the other hand, is a _NoSQL_ database package. There are pros and cons to using a relational (i.e. SQL-based) database and a NoSQL database, and it's up to you to decide which is better for your application.

  • @verryondrums
    @verryondrums 4 роки тому +1

    Is there any possibility to see the data stored in the boxes?

  • @Toasticuss
    @Toasticuss 4 роки тому +2

    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.

    • @el4040
      @el4040 3 роки тому

      thank you

  • @keithbacalso9433
    @keithbacalso9433 2 роки тому

    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`.

  • @glmvnhermawan3062
    @glmvnhermawan3062 4 роки тому

    How about angel dart ? Work's in progress? I'm really can't wait

    • @ResoCoder
      @ResoCoder  4 роки тому +1

      Backend tutorials are heavily WIP, but I can assure you that they're coming!

  • @andrewjackson1833
    @andrewjackson1833 4 роки тому +4

    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

  • @AlexanderSiems
    @AlexanderSiems 3 роки тому +2

    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()),
    );
    },
    );
    },
    );
    }
    }

  • @RNMERIA
    @RNMERIA 4 роки тому +1

    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

    • @JeremyWestAU
      @JeremyWestAU 3 роки тому

      Did you ever manage to resolve this? I have the same issue and literally can not find a solution.

    • @RNMERIA
      @RNMERIA 3 роки тому

      @@JeremyWestAU sorry cant recall it nw

  • @oliverbytes
    @oliverbytes 4 роки тому

    What's next for Hive? :(

  • @kasandrop
    @kasandrop 4 роки тому

    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.

  • @dearvivekkumar
    @dearvivekkumar 3 роки тому

    What path we should give for flutter web?

  • @officialismailshah
    @officialismailshah 2 роки тому

    Your content saved my day.... ❤️❤️❤️❤️ Great content...... Keep posting bro you are amazing.....

  • @shubhamtariyal439
    @shubhamtariyal439 3 роки тому +6

    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.