Flutter SearchDelegates BuildResults isn'a a valid override
I'm trying to build a networkbased search. It works so far, that I get the results I want from my API. Now I want to build the results but get two error messages I don't know how to resolve.
Error 1:
The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr', is a potentially non-nullable type.\nTry adding either a return or a throw statement at the end.
Error 2:
FoodSearch.buildResults' ('Future Function(BuildContext)') isn't a valid override of 'SearchDelegate.buildResults' ('Widget Function(BuildContext)').
My buildResult:
@override
Future<Widget> buildResults(BuildContext context) async {
var split_kat = query.split('|');
String fumiID = split_kat[2];
FutureBuilder<FutterModell>(
future: FumiFibelAPI.getSingleFood(fumiID),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
default:
if (snapshot.hasError) {
return Container(
color: Colors.black,
alignment: Alignment.center,
child: Text(
'Something went wrong!',
style: TextStyle(fontSize: 28, color: Colors.white),
),
);
} else {
return Container();
}
}
},
);
}
The API for the Future-List:
static Future<FutterModell> getSingleFood(String futtermittelID) async {
const storage = FlutterSecureStorage();
var token = await storage.read(key: "_authToken");
int futtermittel = int.parse(futtermittelID);
var url = Uri.parse(开发者_开发知识库'${Constants.BASE_URL}/futtermittel/$futtermittel');
var headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
};
var body = {
"futtermittel_id": futtermittel,
};
var res = await http.post(url, headers: headers, body: jsonEncode(body));
final result = json.decode(res.body);
return result.map<FutterModell>(FutterModell.fromJson).toList();
}
Thanks for the help!
精彩评论