Flutter typeAhead错误:queryrow不是字符串的子类型

时间:2020-07-07 17:05:23

标签: flutter sqflite

我正在尝试使用typeahead在文本字段中显示建议,但收到错误消息“ queryro不是字符串的子类型”

Future<List<dynamic>> _getSuggestions(String query) {
return OrderProvider.db.rawQuery(
    "select TypeOfProduct from Items where TypeOfProduct = ?", [query]);

} **这是我用来从数据库中获取数据的代码**

TypeAheadFormField(
              textFieldConfiguration: TextFieldConfiguration(
                controller: this._typeController,
                autocorrect: true,
                autofocus: true,
                decoration: InputDecoration(hintText: "Product Name"),
              ),
              suggestionsCallback: (suggestion) async {
                return _getSuggestions(suggestion);
              },
              itemBuilder: (context, suggestion) {
                return ListTile(
                  title: Text(suggestion),
                );
              },
              onSuggestionSelected: (suggestion) {
                this._typeController.text = suggestion;
              },
            ),

1 个答案:

答案 0 :(得分:0)

OrderProvider.db.rawQuery(
    "select TypeOfProduct from Items where TypeOfProduct = ?", [query]);

这将返回一个List<Map>(如果您使用的是sqfLite),则RecommendationsCallback会将该列表传递给itemBuilder,但是itemBuilder使用这些建议来构建Text Widget(Text期望类型为{{1 }},而不是String类型。因此您可以在Map方法中使用return来返回List或执行类似操作之前先缩小Map

_getSuggestions(String query)