方法 'firstWhere' 没有为 flutter 中的类型 'Object' 定义

The method 'firstWhere' isn't defined for the type 'Object' in flutter

这是我遇到两个错误的代码。 我得到的第一个错误是-“未为 flutter 中的对象定义方法 'firstWhere'”,第二个错误是-“无法将参数类型 'Object?' 分配给参数类型 'List'"

我是从 api 获取数据并使用这些东西的新手,所以我不确定如何缩短它。

                  FutureBuilder(
                    future: countryList,
                      builder: (context,snapshot){
                      if(snapshot.hasData){
                        return TypeAheadFormField(
                          textFieldConfiguration: TextFieldConfiguration(
                            controller: this._typeAheadController,
                            decoration: InputDecoration(
                              hintText: 'Type here country name',
                              hintStyle: TextStyle(fontSize: 16),
                              border: OutlineInputBorder(
                                borderRadius: BorderRadius.circular(15),
                                borderSide: BorderSide(
                                  width: 0,
                                  style: BorderStyle.none,
                                ),
                              ),
                              filled: true,
                              fillColor: Colors.grey[200],
                              contentPadding: EdgeInsets.all(20),
                              prefixIcon: Padding(
                                padding: EdgeInsets.only(left: 24.0, right: 16.0),
                                child: Icon(
                                  Icons.search,
                                  color: Colors.black,
                                  size: 28,
                                ),
                              ),
                            ),
                          ),
                          suggestionsCallback: (pattern) {
                            return _getSuggestions(snapshot.data, pattern);

                          },
                          itemBuilder: (context, suggestion) {
                            return ListTile(
                              title: Text(suggestion.toString()),
                            );
                          },
                          transitionBuilder: (context, suggestionsBox, controller) {
                            return suggestionsBox;
                          },
                          onSuggestionSelected: (suggestion) {
                            this._typeAheadController.text = suggestion.toString();
                        setState(() {
                          summaryList = covidService.getCountrySummary(
                              snapshot.data! .firstWhere((element) => element.country == suggestion).slug);

                        });
                          },
                        );
                      }
                      else return Text("Loading...");
                      }
                      ),
                    FutureBuilder(
                      future: summaryList,
                      builder: (context,snapshot){
                           if(snapshot.hasData){
                              return Final_Data(summaryList:snapshot.data);
                           }
                           else if(snapshot.connectionState==ConnectionState.active){
                             return Text("Connections state");
                           }
                           else if(snapshot.hasError){
                             return Text("Error");
                           }
                           else return Text("Eroro adl");
                      },
                    ),

错误...

The method 'firstWhere' isn't defined for the type 'Object'.
The argument type 'Object?' can't be assigned to the parameter type 'List<CountrySummaryModel>'.

您尝试过使用泛型吗?为您的 FutureBuilder 指定特定类型,例如:

FutureBuilder<List<String>>(
// your code here
);