sqflite

How to do a database query with SQFlite in Flutter

别说谁变了你拦得住时间么 提交于 2020-05-10 14:14:24
问题 How do you query data from SQLite database in Flutter using the SQFlite plugin? I have been working on learning this recently, so I am adding my answer below as a means to help me learn and also as a quick reference for others in the future. 回答1: Add the dependencies Open pubspec.yaml and in the dependencies section add the following lines: sqflite: ^1.0.0 path_provider: ^0.4.1 The sqflite is the SQFlite plugin of course and the path_provider will help us get the user directory on Android and

Is there a way to check the database version in a flutter app using sqflite?

不打扰是莪最后的温柔 提交于 2020-05-08 05:37:09
问题 I am pretty new to flutter and I have some questions about how database version control works for these apps with sqflite. I have made a database file in my assets folder that is copied onto the device of the user when the app is launched. I am wondering if there is any way to check the current version the user has of the database file, so that it does not have to be copied over every time? Case: I make an update to the database file that is shipped with an app update in the google play store

(UPDATE: How to store List<String> data type in sqflite) sqflite error: DatabaseException(java.lang.String cannot be cast to java.lang.Integer)

我与影子孤独终老i 提交于 2020-04-17 22:43:27
问题 I have a sqflite database with a table set up with all columns aside form the unique key set to BLOB data type. The intent is to store as binary data. I'm very new to dart and flutter, so I'm keeping things as simple as possible. I have int , double , String , List<String> , Map<String:String> , and DateTime data going into these columns. I am using the .insert() function, not the .rawInsert() function. In my TEST application there is no problem whatsoever with either string or int going into

how to make drop down in flutter using split for removing comma on column value of sqflite database

孤街浪徒 提交于 2020-01-25 08:56:04
问题 i want dropdown of stages in flutter which values come from sqflite database. the sample value in json is in below format and these values are store locally. there are two dropdown if i select 'teacher' pipeline then it's id 54 was passed to future builder of stages's dropdown and i want to select one stage. { "id": 54, "name": "teacher", "stages": "{\"advertise\":false,\"interview\":false}", "created_at": "2019-08-23 20:11:54", "updated_at": "2019-08-23 20:12:48", "deleted_at": null }, the

Insert multiple records in Sqflite

北战南征 提交于 2020-01-11 11:38:28
问题 How to insert quickly multiple records in sqflite ? The standard quickly method is: await database.insert(table, object.toMap()) But I don't think that insert record one to one with a cycle is a good idea. Or I can insert all list with a transaction? 回答1: You can use batch in such case. batch = db.batch(); batch.insert('Test', {'name': 'item'}); batch.update('Test', {'name': 'new_item'}, where: 'name = ?', whereArgs: ['item']); batch.delete('Test', where: 'name = ?', whereArgs: ['item']);

How can I auto-update Text according to fetched value from Database using Flutter?

陌路散爱 提交于 2020-01-05 04:23:09
问题 I fetched counting of a total number of records from Sqflite database and I display it on the Dashboard page but records counting is not increased when new record added, need to reopen the page to view changes? So how can I make it auto-update when a new record added? Databse Future<int> getSubCount() async { Database db = await this.database; return Sqflite.firstIntValue(await db.rawQuery("SELECT COUNT(*) FROM $subTable")); } int subjects; void _getCount() async { final int count = await db

Flutter - How to update the table structure in Sqflite?

强颜欢笑 提交于 2019-12-24 11:58:50
问题 My app is in production and I want to manage user data when user updates the app without loss of their data, how can I achieve this with sqflite . Explicitly I want to add a column and delete another. 回答1: You can probably add a column using raw sql, but sqlite (and thus sqflite) doesn't support dropping a column. For that you would need to do the following: increase the database version number in onUpgrade copy the old database columns to a temporary table delete the original table create a

How to do a database insert with SQFlite in Flutter

廉价感情. 提交于 2019-12-23 02:00:54
问题 How do you insert data into a database in Flutter using the SQFlite plugin? There are a number of problem solving questions out there but none that I could find to add a canonical answer to. My answer is below. 回答1: Add the dependencies Open pubspec.yaml and in the dependency section add the following lines: sqflite: ^1.0.0 path_provider: ^0.4.1 The sqflite is the SQFlite plugin of course and the path_provider will help us get the user directory on Android and iPhone. Make a database helper

Flutter: Selected value doesn't display in the dropdown

最后都变了- 提交于 2019-12-23 01:15:13
问题 I'm populating cities name from SQLite database and trying to display as a drop down list. I make it work by following a tutorial, but having a small issue. The selected value is not displayed in dropdown, it keep displaying default hint value. However, I was able to assign and retrieve correct selected value. Here is my code: cities.dart class Cities { int id; String name; Cities(this.id, this.name); Cities.fromMap(Map<String, dynamic> json) { this.id = json["id"]; this.name = json["name"];

How to create multiple tables in a database in sqflite?

狂风中的少年 提交于 2019-12-19 17:40:07
问题 Im building and app with flutter that uses SQLite database. I have created first table using this piece of code: void _createDb(Database db, int newVersion) async { await db.execute('''CREATE TABLE cards (id_card INTEGER PRIMARY KEY, color TEXT, type TEXT, rarity TEXT, name TEXT UNIQUE, goldCost INTEGER, manaCost INTEGER, armor INTEGER, attack INTEGER, health INTEGER, description TEXT)'''); } Table gets created and I can access it without problems. Unfortunately I cannot include more than 1