I have created a SQFlite database for my app which is working very well. Basically, the app is to create a list of my client's company details. The company name appears in an Expansion Tile, and once you open the tile, you see the rest of the company's details. I know how to arrange the tiles in either descending or ascending order, but is there a way to arrange according to alphabetic order based on the company name? Thus, can one arrange the tables in SQFlite in alphabetic order instead of ASC or DESC? When my client's details are added dynamically, I want them to be arranged in alphabetic order so that it makes more sense. Thank you so much for any help.. I have tried to find a comment on this on Stackoverflow, but don't seem to be able to find one.
Ok, I managed to figure this out. My question really shows my inexperience. Anyway, Query has a orderBy property. In my database I created the following code:
Future<void> _createDB(Database db, int version) async {
await db.execute('''
CREATE TABLE todo(
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
name TEXT,
phone TEXT,
fax TEXT,
email TEXT,
street TEXT,
city TEXT,
town TEXT,
code TEXT,
isExpanded INTEGER
orderBy used to be 'id DESC'. It should simply be changed to 'title ASC'. Thus, it will order the sequence by the title in alphabetic order from top to bottom. Here is the code:
Future<List<Todo>> getTodo() async {
final db = await database;
// query the database and save as list of maps
List<Map<String, dynamic>> items = await db.query(
'todo',
orderBy: 'title ASC',
);
Thus, the correct question is not how to order in alphabetic order, but how to order based on title (which is the company name in my example) in ASCending order.