我正在尝试使用SearchDelegate制作自定义应用栏,但出现错误。我正在关注几个教程,但是它们“太老了”。新版本的“ SearchDelegate”具有更多需要覆盖的方法。当我单击条形按钮时发生错误。
appBar: AppBar(
centerTitle: true,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {
showSearch(context: context, delegate: DataSearch(), query: '123');
},
)
],
),
import 'package:flutter/material.dart';
class DataSearch implements SearchDelegate<String> {
final cities = ["Argentina", "Perú", "Uruguay", "Venezuela"];
final suggestionsList = ["Argentina", "Perú"];
@override
String query;
@override
ThemeData appBarTheme(BuildContext context) {
// TODO: implement appBarTheme
return null;
}
@override
List<Widget> buildActions(BuildContext context) {
return [IconButton(icon: Icon(Icons.clear), onPressed: () {})];
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow,
progress: transitionAnimation,
),
onPressed: () {});
}
@override
Widget buildResults(BuildContext context) {}
@override
Widget buildSuggestions(BuildContext context) {
// TODO: implement buildSuggestions
return ListView.builder(
itemBuilder: (context, index) => ListTile(
leading: Icon(Icons.location_city),
title: Text(suggestionsList[index]),
),
itemCount: suggestionsList.length,
);
}
@override
void close(BuildContext context, String result) {
// TODO: implement close
}
@override
// TODO: implement keyboardType
TextInputType get keyboardType => null;
@override
// TODO: implement searchFieldLabel
String get searchFieldLabel => null;
@override
void showResults(BuildContext context) {
// TODO: implement showResults
}
@override
void showSuggestions(BuildContext context) {
// TODO: implement showSuggestions
}
@override
// TODO: implement textInputAction
TextInputAction get textInputAction => null;
@override
// TODO: implement transitionAnimation
Animation<double> get transitionAnimation => null;
}
错误屏幕截图
答案 0 :(得分:1)
请检查是否需要以下有效的官方演示static Future<String> login(String username, String password) async {
var url = _session._getUrl('/auth/login');
var map = new Map<String, dynamic>();
map['username'] = username;
map['password'] = password;
final response = await http.post(url, body: map);
var jsonResponse = convert.jsonDecode(response.body);
var cookies = response.headers['set-cookie'];
if (cookies != null) {
var csrf = _session._getCSRF(cookies);
LocalStorage.instance.setString('CSRF', csrf);
print(csrf);
}
return jsonResponse['msg'];
}
您可以在
工作演示
完整代码
buildResults
答案 1 :(得分:0)
您尝试实现SearchDelegate类的接口。但是您的CustomSearchDelegate应该扩展该类。
更改:
class DataSearch implements SearchDelegate<String>
至
class DataSearch extends SearchDelegate<String>