Searching in Database – Sqlite Flutter

i miss something in my code, i use an existing database (sqlite) in my mobile app, and i want to add a search bar to it, everythings works fine, but the result in the emulator is like this :

{content: name1}

{content: name2}

{content: name3}

i want just the names, thank you for your help !

This is my code :

String text;
List course;

void _query (text) async {
Database db = await DatabaseHelper.instance.database;
List<Map> result = await db.rawQuery("SELECT content FROM table WHERE content LIKE '%${text}%'");

setState(() {
  result.forEach((element) {
  print(element);
  course = result;
  });

});
} 


 body:Column(
    children: [
      Padding(
        padding: const EdgeInsets.all(10.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(
              Icons.search,
              color: Colors.grey,
            ),
            SizedBox(
              width: 20,
            ),
            Container(
              width: MediaQuery.of(context).size.width - 100.0,
              child: TextField(                   
                decoration: InputDecoration(
                  hintText: search ... ,
                ),
                onChanged: (String text) async {
                  _query(text);
                },
              ),
            ),
          ],
        ),
      ),
      Expanded(
        child: ListView.builder(
                padding: const EdgeInsets.all(14.0),
                itemBuilder: (context, index) {
                  return Column(
                    children: [
                      Divider(
                        height: 20,
                      ),
                      Material(
                        color:  Colors.grey,
                        child: ListTile(
                          title: Text(
                            course == null
                                ? 'loading'
                                : '${course[index]}',
                            style: TextStyle(                                    
                                color: Colors.black),
                          ),
                        ),
                      )
                    ],
                  );
                }
              ),
          ),
        ],
      ),


Read more here: https://stackoverflow.com/questions/64404274/searching-in-database-sqlite-flutter

Content Attribution

This content was originally published by swing13 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: