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),
),
),
)
],
);
}
),
),
],
),
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…