('Widget? Function(BuildContext)') 不是 'SearchDelegate.buildResults' ('Widget Function(BuildContext)') 的有效覆盖

('Widget? Function(BuildContext)') isn't a valid override of 'SearchDelegate.buildResults' ('Widget Function(BuildContext)')

我们最近将我们的应用程序迁移到空安全,现在我们的 SearchDelegate 返回以下错误

'AddressSearch.buildResults' ('Widget? Function(BuildContext)') isn't a valid override of 'SearchDelegate.buildResults' ('Widget Function(BuildContext)').

这似乎与结果有关,但我们看不到自从进入空安全后这有何变化

class AddressSearch extends SearchDelegate<Suggestion?> {
  AddressSearch(this.sessionToken) {
    apiClient = PlaceApiProvider(sessionToken);
  }

  final String sessionToken;
  late PlaceApiProvider apiClient;

  @override
  String get searchFieldLabel => 'Enter Task Suburb';

  @override
  List<Widget> buildActions(BuildContext context) {
    return [
      query.isNotEmpty
          ? IconButton(
              tooltip: 'Clear',
              icon: const Icon(Icons.clear),
              onPressed: () {
                query = '';
              },
            )
          : const SizedBox()
    ];
  }

  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
      tooltip: 'Back',
      icon: Icon(Icons.adaptive.arrow_back, color: Colors.black),
      onPressed: () {
        close(context, null);
      },
    );
  }

  @override
  Widget? buildResults(BuildContext context) {
    return Text(query);
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    return FutureBuilder(
        future: query.isEmpty
            ? null
            : apiClient.fetchSuggestions(
                query, Localizations.localeOf(context).languageCode),
        builder: (context, AsyncSnapshot snapshot) => query.isEmpty
            ? Container(
                padding: const EdgeInsets.all(16.0),
                child: const Text(''),
              )
            : snapshot.hasData
                ? ListView.builder(
                    itemBuilder: (context, index) => ListTile(
                      title: Text(
                          (snapshot.data[index] as Suggestion).description!),
                      onTap: () {
                        close(context, snapshot.data![index] as Suggestion?);
                      },
                    ),
                    itemCount: snapshot.data!.length,
                  )
                : const SizedBox());
  }
}

只需删除

中的问号
Widget? buildResults(BuildContext context) {

很喜欢

Widget buildResults(BuildContext context) {