SQLite in Flutter

Поділитися
Вставка
  • Опубліковано 31 лип 2024
  • This video goes over the SQLite schema management setup we use in production Flutter applications.
    Written tutorial:
    Timestamps
    00:00 - Intro
    00:58 - Code Overview
    01:27 - SQLite setup
    03:06 - Schema creation
    08:41 - SQL CRUD
    12:26 - Using Database in App
    14:37 - SQL Migrations
  • Наука та технологія

КОМЕНТАРІ • 120

  • @jaspreetkaur-mo2dr
    @jaspreetkaur-mo2dr 3 роки тому

    Awesome man, Another again content. Thanks, Man

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

    This is the video that i am waiting for thank you so much.

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

      You're welcome! I hope it's worth the wait.

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

      @@FilledStacks Definitely worth it.

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

    I definitely knew you would do it Thank u sooo much filled stacks

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

      You're welcome :) Hopefully it's worth it.

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

    Your tutorials are best and consise

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

      Thank you. I try my best to keep things easy to understand

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

    You are amazing man ♥

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

    I love your content always fantastic quality

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

      I really appreciate the kind words and leaving the comment. Thank you

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

      @@FilledStacks Thanks to you for sharing such amazing content

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

      @@workflop4117 😊

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

    This is so cool.
    I'll waiting for the serie about doing Offline First with: REST and SQLite and FilledStacks. Great Work Dane!

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

      Thank you. I don't think there will be a series about that. I've shown how I do api, now sqlite so there's nothing left in that set of videos you asked for.

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

      @@FilledStacks You could give an example of syncing between the SQLite db in the app and the API!

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

      @@steveandjodee hey, I've seen this idea before. You don't actually sync between the two. Or at least in my experience of making an app offline. I store some of the data, that I won't want the user to request locally in the db. Then I'll always show that first and then fetch updated in the background and update again. There are waaaaay too many ways to do it and it all depends on the api capabilities. What you can get as a single request and what you can't get in addition what you want to be offline etc.

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

      @@FilledStacks I would love to see tuts for building Offline First app. While I do agree it's an architecture choice, I haven't seen clear example of one of the architectures in Flutter using API and SQLite. Most problems occur when I have to sync with multiple devices or managing multiple offline state API requests when one of devices comes online after some offline time. And simply answering use Firebase is not an option.

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

      @@ebelevics Luckily I've never had to build apps like that so I won't be able to make a video about that. It's not something that I think of often. The furthest scenario i've had to use local storage for is to ensure things are on screen while we fetch the real data. i don't manually do "Sync when connected" , I don't "Sync between devices" if the user has multiple accounts. That's all "naturally" taken care of by my startup logic. Get everything needed in my startup view, and then continue into the app when it's ready. So I basically always show fetched data first unless there's no connection. But then the apps I build won't work so I just tell them that and don't do much about it. Can't order from a food delivery service without internet :D so we can just not handle those scenarios because it'll bring no benefit to the customer or clients. And we do have "sync when connected" functionality, but it's all handled by firestore haha, so won't be able to make a video about that on SQL.

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

    Dane my man you absolutely lifted me from scratch in flutter development... Cannot thank you enough.
    And what the hell is this Riverpod thing. Would love to see your views on it.

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

      You're very welcome. It's my pleasure to share the knowledge. I haven't used it yet. I will take a look at it and see how much benefit we can get from it.

  • @hurbes101
    @hurbes101 3 роки тому +3

    I was waiting for this tutorial for so long. it was greatly informative and helpful, thank you. Please make a video on GraphQL with flutter is possible

    • @FilledStacks
      @FilledStacks  3 роки тому +3

      I'm happy to hear that! and I'm happy that you got some value from it. I'm definitely doing GQL soon. Have to go into a bit of a crunch for a client app so we can deliver so I will probably be back in about 2 or three weeks only. I actually have a GQL implementation for this client so I can share that when I get back.

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

      @@FilledStacks I'll be eagerly waiting for it :)

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

      @@hurbes101 :D

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

    💙💙💙 thanks FilledStack

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

      You're welcome. Thanks for watching.

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

    Thanks dane! 🙌

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

    Thank you Dane.

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

    Thank you so much

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

      It's my pleasure to share it! Thanks for watching.

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

    I really appreciate your work. Keep it up bro. Also do a tutorial on localization. Thanks for the knowledge you are sharing ❤️

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

      Hey Hey, I planned to do one but never got around too it. There's quite a lot of functionality to go through and to add into my package before I can do that. But it's on the list of videos to make.

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

      Thanks, I'm looking forward to that.

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

      @@isyedaliraza Hopefully one day soon

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

    Thanks for this. Also covering Moor or Hive will be great.

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

      Resocoder has a good series on moor so I don't think there's anything that I can add. If I ever use hive in production I will share what I learned, at the moment i haven't so I don't have anything to share about it.

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

      @@FilledStacks yes you are totally right, thank you.

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

      @@h3w45 😄

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

    Merci Monsieur.

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

    you good man

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

    Pretty nice information here. Can I suggest you to follow up this SQL series on how to back up the DB to either google drive or even better dropbox, and restore the DB back again to a simulated brand new device?.

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

      Thank you. I've never done that, the way I handle that is by storing all the information on the server. The database functionality is purely to provide offline capabilities when there's no connection so we show something and not nothing.
      I've never done a DB backup. Basically on start I get whatever info I need from the api and keep it locally.

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

    Damn, so many things to dissect here... personally never used FutureViewModel. Going to look into that now.. very nice Tutorial! Thank you!

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

      Thanks! It's pretty basic, if your view DEPENDS on data returned by a Future then use the future viewmodel. Give the future to the futureToRun function and it'll run the future, set the view to busy until the data is returned. When the data comes back it sets the data property on the model and fires onData incase you want to do something when the data is returned. It also catches the errors for you and sets it to the error object. it also fires the onError function in case you want to do something when the error happens like show a dialog, etc. Very useful. It removes quite a bit of boilerplate.

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

      @@FilledStacks I see, I think I'll try to refactor a bit of my app to see how it goes when I'm done with my other stuff.Thank you for this..
      On an unrelated note, I was updating my packages and got this error: Because "app" depends on stacked_themes ^0.2.0 which depends on get_it ^4.0.4, get_it ^4.0.4 is required.
      If you have the time, can you update your package requirements?

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

      @@wickedgummybear3104 I can definitely update and push that.

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

      @@FilledStacks It's all working perfectly fine as it is, but I just always feel a bit better when everything is tidy and up to date hahaha. Thank you! No hurries though!

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

      @@wickedgummybear3104 haha, you and me both :D :D It's a much better feeling and migration process as well when you do all the incremental updates along the way instead of a massive refactor months down the line. We think the same!

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

    Hi, how to create multi-tables with foreign key with this method? and in openDatabse, there isn't a path, only a datebase name, do we need a path too? thank you!

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

      Hi, that would all be done in your SQL files. However you would do that in normal sql you'd do it the same way here, if that's supported in sqlite. And the path is the name of the DB.

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

    Great video again! How would you organize multiple models in the database_service file? Would you extract the CRUD functions to a file for each model?

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

      thank you! I'm a bit confused by the term "Multiple models in a database_service file" the data models I usually keep in separate files. When there are multiple actions for each model I do split them up at some point but I've found it more difficult to maintain in the long run that way. Unless each of them has access to the same database, but I like having a unified api for all the DB actions. So that's a personal thing on my side. You could split the actions for ORders and posts into separate repositories if that feels better for you.

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

      @@FilledStacks In the example above you have only one model - Todo. The methods ( getTodos, addTodo etc.) that manipulate this model are in DatabaseService. In case that the app has multiple models, where do you place all the methods specific to these models? Still in the DatabaseService? For an app with 10 models and 5 methods each, it can be a file with 50 methods. I'm trying to get my head around how you organize such a scenario. Thank you

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

      @@cautaro I see, i've done both. Splitting the models between multiple classes and keeping it in 1. I like keeping it in 1 more than splitting it into 10 different classes. makes the unit testing easier and the maintenance as well. It might be how i implemented it but I still liked having 1 file more for the maintenance.

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

    Hi, I have a sqlite database I want to 'secure' it using sqlcipher, is this the correct way, have you ever seen an example of using this, thanks Pierre

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

      Hi Pierre, I have not seen an example of this and I also have never used sqlcipher. I've never stored sensitive info locally so I don't ever have the requirement for a secure db.

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

    Thanks I was working with this package , can we also save the state of the widget like for example a process bar

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

      I wouldn't recommend that. I'd rather use a no sql db for that like hive so that you don't have to update your schema everytime you want to save data from a different widget.

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

      I was trying Hive but Idk what’s wrong with it , the package is not stable though I have worked with before but now it’s not working

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

      Can you create a discord channel where you can add people working in flutter so that they help each other out

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

      @@rishabhsharma3821 Yeah we have a channel on Slack join.slack.com/t/filledstacks/shared_invite/zt-hqvqnd50-trS3YfEsL~2LQXfi9XjFBw I don't like discord because everthing is confusing and you can't follow a conversation. Slack has threads so it works out better.

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

      @@rishabhsharma3821 I was using Hive for a while, but also struggeling. At some point it was not doing something which it was supposed to do and didnt give an error either. SQL is a bit too much power for my needs at the moment so I switched to Sembast. It seems to do the trick.

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

    Next video suggestion how to manage onboarding screens(the screens should only be shown when the user first installed the app)

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

      Thanks for the suggestion. I've seen quite a few videos on that. You just use shared preferences, at the end of onboarding you set a value to true. If it;s false when you start the app you show the on boarding. If it's not you skip it.

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

    Can you please do Wysiwyg ?
    How to render properly data from wysiwyg stored in firestore? I mean from wysiwyg web to firestore to data displayed nicely in flutter. Thanks 👏

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

      Hey, I have no idea what that is so I doubt I'll be able to make a video about it.

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

    I'm having a issue with my flutter code, Where can I ask ?

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

      You can join our slack channel and ask there join.slack.com/t/filledstacks/shared_invite/zt-hqvqnd50-trS3YfEsL~2LQXfi9XjFBw

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

    have you considered using the hive package it saves much boilerplate and it is fast

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

      I have but the query functionality is limited. I needed the query relations for the data that was being stored

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

      @@FilledStacks i had the same problem but i solved it by adding adapters to each model it should work fine

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

      @@ajnaf7277 Thanks for that info. I'll look into that again when we get around to our next project. I Appreciate you sharing that.

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

    Any experience with using Floor? What are your thoughts on it?

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

      None, I've never used it. The furthest I got was watch the @resocoder video on it to see what it's about. But I've never used it in production.

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

    Unfortunately is not possible to use SQLite in Flutter for web.

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

      If I had to choose a db to use I wouldn't go with SQLite for local storage. Something without schema management would be my first choice. If I had to do advanced queries then it would have to be sqlite other than that you can do with a noSql db that has browser support.

  • @JuanPerez-vv5lk
    @JuanPerez-vv5lk 3 роки тому

    is this technique valid as of today july 2021 ?

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

      Yes. still valid. we use it in production.

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

    Hey, my database is getting deleted whenever I hot restart or also when the app is removed from recent apps and opened again. Any idea how to solve this?

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

      Hey, I don't know why that would be happening. I use the sql_migration_service and it solved that for me.

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

      @@FilledStacks I got the solution, thanks for replying though!

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

      @@jaineelmamtora8208 Awesome. What did you have to do?

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

      @@FilledStacks Well, I was not querying the database properly.

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

      @@jaineelmamtora8208 aaaaaah, that can happen. I'm a SQL noob and that has definitely happened to me before.

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

    Great video, could you please share the source code for this tutorial?

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

      Thank you. It's with all the other tutorials at github.com/filledstacks/flutter-tutorials

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

    Can we use Moor here? Are there any downsides of using Moor?

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

      yes you can. I don't know of any downsides, haven't used it before.

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

      @@FilledStacks you should check it

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

      @@abraiyan7984 I don't need SQLite outside of the basic functionality and I needed a bit more manual control over models and mapping of the data. But i have seen the reso coder series on it.

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

      @@FilledStacks Thanks, man. It will be great to know what kind of database you use for your projects. And I have a request. Make a video on the NoSQL database or a series of videos.

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

      @@abraiyan7984 All the code I share comes from production solutions. So at the moment we're using sqlite. The only NoSql db we use is through firestore which we're using for 2 apps at the moment, another 2 a few months ago. I'd highly recommend fireship.io instead of my content for no sql db content. Jeff has a way better set of knowledge around it. I only learn what I need to to overcome a problem at hand.

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

    Please make a video about handle API and exception and other concept related. I get stuck with this so long :(((

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

      Hey, I handle mine the normal way, I surround the call with a try catch and print out the errors in the catch statement.

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

      many problem around they such as many different responses corresponding to many status codes, how catch it and print error message inside different json type ... :((

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

      @@nero9061 I check for certain status codes and then handle it according to how my app should handle that based on what it means coming from the api. I just add if statements and then do what needs to be done per response code. I have one function that handles all the actual requests so I can handle the response codes in one place and use that function for every endpoint we have.

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

      @@FilledStacks but when i handle in one function actually making request, with one responsebody, I have to call fromJson function in different classes to decode to have actual message to show in dialog, and in every classes i said, the model class is totally different. So I can't return the actual message I want to show from where making request to the view model to show dialog or something like that. Still so confused ...

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

      @@nero9061 Sorry man, i have no idea what you mean. You can just return your response in the way you want it. If you're handling the same response differently in many places that should work fine as well.

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

    Reso is awesome hahahaha it's true

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

    Bruh, you rock!!!!!! Thank you so much for this freaking good video!
    Bruh, I've gotta question:
    Is your website: "www.filledstacks.com" backend and front-end made with flutter for web?
    Thanks.

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

      Thanks!! There's actually no backend for FilledStacks. It uses all locally hosted data. The tutorials are generated from markdown files and stored in a local graph ql database. I use Gridsome for my website, it's built ontop of VueJs.

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

    It's pronounced "ess cue light" according to Richard Hipp, and "ess cue ell" for the abstract language (and *never* "sequel" yuck), regardless of how you've been hearing it all these years. Monty Widenius insists on "my ess cue ell" for the app/framework later named Maria, and I've heard "ess cue flight" for the Flutter package.

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

      Thanks, i do always struggle to find the correct ways to pronounce things. I like using the SQL naming SeeQuel Lite. But now I know it's wrong haha.

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

    lol u still on Earth thought u moved to Mars heheh...

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

      haha! Nooo, I love earth too much. :)