Chapter 6

  1. What happens when you call the openDatabase() method?
    The sqflite library has an openDatabase() method, that opens and returns an existing database. The method takes the path of the database to be opened and the version of the database. The optional onCreate parameter will be called if the database does not exist. There you can specify the instruction to create the database.

  2. What's the difference between the rawQuery() and query() methods of a database object?
    Both are methods to retrieve data from a database. The rawQuery() method takes a SQL instruction, the query() method is a helper where you specify the table, a where filter, and a whereArgs parameter. An example of the two methods is shown in the following code block:

List places = await db.rawQuery('select * from items where idList = 1');
List places = await db.query('items', where: 'idList = ?', whereArgs: [1]);
  1. How do you use a factory constructor? When should you use it?
    A factory constructor overrides the default behavior of the constructor of a class, instead of creating a new instance, the factory constructor only returns a single instance of the class. The syntax to create a factory constructor is as follows:

static final DbHelper _dbHelper = DbHelper._internal(); DbHelper._internal();
factory DbHelper() {
return _dbHelper;
}
  1. What's the purpose of a Dismissible widget?
    A Dismissible is a widget that detects the left and right swipe gestures of the user and shows an animation that removes an object. Using Dismissible is ideal when you want to delete an item.

  2. How do we use the where and whereArgs parameters of a query() method?
    You use where and whereArgs when you want to filter the data retrieved from the query() method. The where parameter takes field names and the comparison operators and whereArgs takes the values. An example is shown in the following code block:

List places = await db.query('items', where: 'idList = ?', whereArgs: [1]);
  1. When should you use model classes in an app?
    Model classes create objects that mirror the structure of the tables in a database: this makes the code more reliable, easier to read, and helps prevent data inconsistencies.

 

  1. When would you use a SnackBar?
    A SnackBar is a widget that shows messages at the bottom of your app. Generally, you use a SnackBar to inform your users that an action has been performed.
  1. What's the syntax of an insert() method on an SQLite database?
    The insert() asynchronous method allows you to specify the name of the table where we want to insert data, a Map of the data that you want to insert, and optionally a conflictAlgorithm that specifies the behavior that should be followed when you try to insert a record with the same ID twice. It will return the ID of the new record that was inserted. Take a look at the following example:
int id = await this.db.insert( 'lists',list.toMap(), conflictAlgorithm: ConflictAlgorithm.replace, );
  1. What is the purpose of the key in a Dismissible widget?
    The key in a Dismissible widget is used to uniquely identify the item that will be deleted.

  2. When would you use a FAB?
    The FAB, or Floating Action Button, is a circular button that you can use for the main action on the screen. If you have a list of items, the main action could be adding a new item.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.129.90