在现有数据库文件中搜索-Sqlite颤振
我有一个现有的数据库,我想添加一个搜索栏,这样用户就可以从数据库中搜索内容了,我跟着,我不知道缺少了什么 这是我使用的查询在现有数据库文件中搜索-Sqlite颤振,sqlite,flutter,dart,Sqlite,Flutter,Dart,我有一个现有的数据库,我想添加一个搜索栏,这样用户就可以从数据库中搜索内容了,我跟着,我不知道缺少了什么 这是我使用的查询 "SELECT * FROM wod WHERE content LIKE '%${text}%'" 我得到了这个错误: E/flatter(10380):[错误:flatter/lib/ui/ui\u dart\u state.cc(166)] 未处理的异常:NoSuchMethodError:方法“rawQuery”无效 调用null 这是我的密码
"SELECT * FROM wod WHERE content LIKE '%${text}%'"
我得到了这个错误:
E/flatter(10380):[错误:flatter/lib/ui/ui\u dart\u state.cc(166)]
未处理的异常:NoSuchMethodError:方法“rawQuery”无效
调用null
这是我的密码
class _Wod3State extends State<Wod3> {
Database database;
@override
void initState() {
// TODO: implement initState
openDatabase('wod.db',
version: 1,
onCreate: (Database db, int version) async{
database = db;
});
super.initState();
}
class\u Wod3State扩展状态{
数据库;
@凌驾
void initState(){
//TODO:实现initState
openDatabase('wod.db',
版本:1,,
onCreate:(数据库数据库,int版本)异步{
数据库=db;
});
super.initState();
}
这是建筑商
@override
Widget build(BuildContext context) {
if(database == null){}
return Container(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 70.0,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
child: Container(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Icon(Icons.search),
Container(
width: MediaQuery.of(context).size.width - 100.0,
child: TextField(
decoration: InputDecoration(
hintText: 'Search ...',
),
onChanged: (String text) async{
List<Map> res = await database.rawQuery(
"SELECT * FROM wod WHERE content LIKE '%${text}%'");
print(res);
}),
)
],
),
),
),
),
),
)
],
),
),
);
}
@覆盖
小部件构建(构建上下文){
如果(数据库==null){}
返回容器(
孩子:填充(
填充:常数边集全部(10.0),
子:列(
儿童:[
填充物(
填充:常数边集全部(8.0),
子:容器(
身高:70.0,
孩子:填充(
填充:常数边集全部(8.0),
孩子:卡片(
子:容器(
孩子:排(
主轴对准:
MainAxisAlignment.spaceBetween,
儿童:[
图标(Icons.search),
容器(
宽度:MediaQuery.of(context).size.width-100.0,
孩子:TextField(
装饰:输入装饰(
hintText:“搜索…”,
),
onChanged:(字符串文本)异步{
List res=await database.rawQuery(
“从wod中选择*内容,如“%${text}%”;
印刷品(res);
}),
)
],
),
),
),
),
),
)
],
),
),
);
}
多谢各位