Database Storage in Flutter using SQFlite

preview_player
Показать описание
Persistent data storage is an important topic in mobile development. Both Android and iOS can take advantage of SQLite, a lightweight SQL database. Sqflite is flutter library to tap into that power on both platforms. This tutorial will walk you through the basic CRUD data operations (Creating, Reading, Updating, and Deleting) using the Sqflite library.

00:00 - Intro
00:36 - Reviewing initial code without Sqflite
04:52 - Creating and opening the database using the Singleton pattern
14:00 - Mapping your database column names to your model fields and vice-versa
17:57 - Writing a function to retrieve all rows from a database table and mapping the results to the model
21:47 - Writing a function to insert a row into the database
23:38 - Retrieving all rows of the table when the list widget initializes and setting the bloc data
26:30 - Inserting a new row and updating the bloc data
29:13 - Test inserting foods and debugging
31:22 - Writing a function to delete a row(s) in the database
33:15 - Writing a function to update a row(s) in the database
34:57 - Deleting a food from the database and updating the bloc
37:39 - Updating an existing food in the database and updating the bloc

Рекомендации по теме
Комментарии
Автор

What other data storage solutions are you interested in? I may do a 2nd part for this topic that goes into more advanced topics like complicated data structures, batch transactions, etc. Depends on how much interest there is for it.

TheFlutterFactory
Автор

have been searching for a video that explains this perfectly... saving Bool to database and retrieving it... thanks 👍

brighterpress
Автор

Thank you for a great example of using SQLite database in Flutter

domontowicz
Автор

Thank you for this explanation, it was very useful to write down a part of the code for my dissertation!

gionachiodini
Автор

Thank you for these videos. I am so glad its current as well. Going to go through most of them. Thanks

Jo-tbur
Автор

Thanks for your video, it was helpful

SavitskyVadim
Автор

Great vid thanks a lot! Helps alot in developing my first app. Appreciate if you could show how do we do a search and filter data in an sqflite database.

mohamednizam
Автор

Hello curry your courses are great but I can't follow along because you don't start from scratch. Am a self taught developer so most times I depend on YouTube videos. But always start your tutorials from scratch so that beginners can easily follow along. Thank you

austinevick
Автор

Thank you for the video. After recent updates to the bloc, I'm having trouble initializing it in main.dart though.

wickedgummybear
Автор

Hey your video has been really helpful but can you make a video on how to create more than one table in the database!!!! 😅😅😅 It would be really helpful thanx :)

anilshrestha
Автор

Well thanks for the tutorial, it is really helpful but i would like to ask why you call the databaseProvider.db by yourself? after you .add(Event) FoodBloc should call the databaseProvider and Inset or Update regarding to the Event you add. Isn't it the reason we have Bloc ?

yanmaz
Автор

It would be nice to see a tutorial on how to backup this database to a file and then restore it from a file. So that user can backup the data, delete the app, and then redownload the app and restore the data from file

evanwallace
Автор

Hey Curry! Awesome video! I'm so grateful I came across your channel! Thanks very much for the detailed tutorial. It's really useful to new coders like me! I have a question: When I enter a food item into the list then subsequently edit the values, why are the edited values not stored permanently in the database? Each time I close and reopen the app the initial values ( prior to editing the calories for example) are retrieved. I tried this with your source code and seem to get the same results. Have I done something wrong?? Thanks in advance!

abdullahshah
Автор

Neatly explained and easy to follow. Had a question to follow this video. If at all we need to add 'Favourites' will that mean it is a new event?

vivianlobo
Автор

Is there a video showing you building the initial code ?

fred
Автор

30:39

I disagree.
It isn't because you used an arrow function, it is because you access context in the .then of a future called in initState. You cannot guarantee that the context is right. You need to find a better way to call the getFoods. I recomment using a FutureBuilder or, failing that, a Widget Binding Observer.

Yes it seemed to work after you changed it but the problem is that it is timing related.

tahaan
Автор

Thanks for the video. A suggestion to make future tutorials a little more beginner friendly: Could you please have the initial source code (in this instance, prior to sqflite, but with BLoC) in a clearly marked archive folder within the project files? It wasn't very clear at the start where the initial source code was starting from. E.g. Was the code simply continuing from where your BLoC tutorial finished? While the start of the video seemed to imply that, I noticed a number of differences between the completed code in your BLoC tutorial and the code you were showing at the start of the video.

In the end, I realised I had to dig around for the previous versions of the code in github. Many beginners will not realise this, and will get frustrated since simply getting to the starting line with your tutorial is such a scavenger hunt.

shane
Автор

Can I ask why your insert fucntion returns a type of Future<Food> rather than Future<void>?

KAISEI
Автор

I am trying to combine a Sqflite database with the table_calendar flutter package. In order to get only the events from each day, I need a Map<DateTime, List<dynamic>> data structure. Now I know, that the data saved within the Database can be recalled as a List<Class>. How would you pass the data to the Map<DataTime, List<dynamic>> and show the objects within the ListView widget?

salonikidis
Автор

@Cheetah Coding Could you let us know what the issue is where the sqlite items on ListTile do not update after a page change? They update when you update with button, but after the page is changed, they return to the original value. Thank you!

teemoisbaron
welcome to shbcf.ru