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

Поделиться
HTML-код
  • Опубликовано: 30 июл 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

Комментарии • 171

  • @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 :)

  • @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!

  • @ManOnTheMoon2131
    @ManOnTheMoon2131 3 года назад

    This was incredibly helpful. Thank you! Subscribed!

  • @mostafafahimi4588
    @mostafafahimi4588 3 года назад

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

  • @chetan6406
    @chetan6406 4 года назад +1

    Best channels for learning flutter....thankyou

  • @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

  • @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!

  • @danieldey
    @danieldey 3 года назад +2

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

  • @fununterhaltung6556
    @fununterhaltung6556 3 года назад +1

    Thank you very much for this wonderful tutorial!!

  • @AshishGupta16
    @AshishGupta16 4 года назад

    best hive video out there!! thanks :)

  • @ShitIndie
    @ShitIndie 4 года назад +3

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

  • @leotrantruc
    @leotrantruc 4 года назад

    Great video! Thank you so much.

  • @MindzGroupTech
    @MindzGroupTech 4 года назад

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

  • @theflutterboi
    @theflutterboi 3 года назад

    Thank you so much for the tutorial 💙.

  • @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.

  • @mustafashaikh7829
    @mustafashaikh7829 4 года назад +1

    Love your content Sir.....

  • @MrHimanshun
    @MrHimanshun 3 года назад

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

  • @4funrc11
    @4funrc11 4 года назад

    WOW! Impressed... Thx!

  • @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 🤣

  • @brianmanuputty4412
    @brianmanuputty4412 4 года назад

    very useful, thank you

  • @etiennetheodore
    @etiennetheodore 4 года назад

    Thanks like always.

  • @oblakus
    @oblakus 4 года назад

    Great tutorial 👍

  • @SkShofiul
    @SkShofiul 4 года назад

    finally new lightweight database !

  • @Baraka0369
    @Baraka0369 4 года назад

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

  • @burakbirer
    @burakbirer 3 года назад +1

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

  • @radurot7673
    @radurot7673 2 года назад +1

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

  • @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.

  • @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

  • @himanshudhakecha1789
    @himanshudhakecha1789 3 года назад

    helpful, Thanks for sharing

  • @nicolasdupere
    @nicolasdupere 4 года назад

    You are so good.

  • @yemenpoint_com
    @yemenpoint_com 4 года назад

    Thanks boooy your the best

  • @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

  • @easazade
    @easazade 4 года назад

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

  • @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

  • @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 😅

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

  • @ajinata849
    @ajinata849 4 года назад

    epic, this is epic.

  • @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.

  • @ahmadfarhat1014
    @ahmadfarhat1014 4 года назад

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

  • @LexPrimost
    @LexPrimost 4 года назад +1

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

  • @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 😄

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

  • @rtech8779
    @rtech8779 4 года назад

    You are boss bro

  • @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!

  • @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

  • @tahirdevlog2047
    @tahirdevlog2047 4 года назад

    thankss

  • @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..

  • @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..

  • @PaulMcKillop
    @PaulMcKillop 3 года назад

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

  • @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 ?

  • @MoAdel92
    @MoAdel92 3 года назад

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

  • @HarshSingh-hk8fe
    @HarshSingh-hk8fe 3 года назад

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

  • @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.

  • @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.

  • @gourav7315
    @gourav7315 4 года назад

    Please make more Hive Flutter Video

  • @43_arshadsaiyed78
    @43_arshadsaiyed78 3 года назад

    Which plugin you are using for brackets?

  • @igorbondarenko9854
    @igorbondarenko9854 4 года назад

    Thanks for your work, what about floor?

    • @ResoCoder
      @ResoCoder  4 года назад +2

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

  • @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

  • @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

  • @radouaneelayachi4878
    @radouaneelayachi4878 3 года назад

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

  • @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

  • @haviforg
    @haviforg 4 года назад

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

  • @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

  • @ZEEVLOGSzubair_malik
    @ZEEVLOGSzubair_malik Год назад

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

  • @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.

  • @juanmanueljaramillohenao654
    @juanmanueljaramillohenao654 4 года назад

    gracias papi

  • @pradeepkumarreddykondreddy7048
    @pradeepkumarreddykondreddy7048 3 года назад +1

    Where are we defining box name as contacts ?

  • @aminsamad6900
    @aminsamad6900 2 года назад

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

  • @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."

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

  • @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

  • @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.

  • @armagan_gok
    @armagan_gok 2 года назад

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

  • @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

  • @DKSTechnology
    @DKSTechnology 3 года назад

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

  • @ravichudgar
    @ravichudgar 4 года назад

    can we give the primary key in hive ???

  • @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!

  • @officialismailshah
    @officialismailshah 2 года назад

    How can I add unique data in hive box

  • @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

  • @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.

  • @armagan_gok
    @armagan_gok 3 года назад +2

    it has been 2 years you should update codes!

  • @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

    • @verryondrums
      @verryondrums 4 года назад

      Thanks, ran into that as well :)!

    • @alexandrufilipescu1301
      @alexandrufilipescu1301 3 года назад

      I am not sure why I can't add a typeId:0 to registerAdapter()....

  • @adriano_souza
    @adriano_souza 3 года назад

    How I implements this in TDD?

  • @Sampelmind81
    @Sampelmind81 2 года назад

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

  • @verryondrums
    @verryondrums 4 года назад +1

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

  • @haberinvarsa
    @haberinvarsa 2 года назад

    Firebase set do hive ?

  • @billmellis7796
    @billmellis7796 4 года назад

    What linux distro is that?

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

  • @officialismailshah
    @officialismailshah 2 года назад

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

  • @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? :(

  • @dearvivekkumar
    @dearvivekkumar 3 года назад

    What path we should give for flutter web?

  • @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.

  • @luix138
    @luix138 4 года назад

    Sadly It seems hive isn't maintained anymore. Also, I couldn't install the dependency for incompatibility with Flutter SDK. The only way it worked was by removing flutter_test from dev_dependencies.

    • @wickedgummybear3104
      @wickedgummybear3104 4 года назад

      I had the same problem. It helps to use dependency_overrides: dartx: ^0.4.2 ... but honestly I'm having trouble getting any Hive example thing to run properly. Overriding stuff does not make me too happy. Thinking of just trying Moor now..

    • @luix138
      @luix138 4 года назад

      @@wickedgummybear3104
      in pubspec.yaml add:
      hive_flutter:
      git:
      url: github.com/hivedb/hive.git
      path: hive_flutter
      Because this video is a bit old and Hive was modified I had to follow the docs to see what changed
      docs.hivedb.dev
      PS: don't use Hive.initFlutter()
      but do use: import 'package:hive_flutter/hive_flutter.dart';