我在这里学习教程:https://resocoder.com/2020/08/04/flutter-bloc-cubit-tutorial/。
当我到达"Building“部分和在main.dart中时,我有以下问题:

我所犯的错误:
[{
"resource": "/d:/My Programs/learn_dart/weather_bloc/lib/main.dart",
"owner": "_generated_diagnostic_collection_name_#1",
"code": {
"value": "type_argument_not_matching_bounds",
"target": {
"$mid": 1,
"external": "https://dart.dev/diagnostics/type_argument_not_matching_bounds",
"path": "/diagnostics/type_argument_not_matching_bounds",
"scheme": "https",
"authority": "dart.dev"
}
},
"severity": 8,
"message": "'dynamic' doesn't conform to the bound 'StateStreamableSource<Object?>' of the type parameter 'T'.\nTry using a type that is or is a subclass of 'StateStreamableSource<Object?>'.",
"source": "dart",
"startLineNumber": 13,
"startColumn": 13,
"endLineNumber": 13,
"endColumn": 25,
"relatedInformation": [
{
"startLineNumber": 13,
"startColumn": 13,
"endLineNumber": 13,
"endColumn": 25,
"message": "The raw type was instantiated as 'BlocProvider<dynamic>', and is not regular-bounded.",
"resource": "/d:/My Programs/learn_dart/weather_bloc/lib/main.dart"
}
]
}][{
"resource": "/d:/My Programs/learn_dart/weather_bloc/lib/main.dart",
"owner": "_generated_diagnostic_collection_name_#1",
"code": "could_not_infer",
"severity": 8,
"message": "Couldn't infer type parameter 'T'.\n\nTried to infer 'dynamic' for 'T' which doesn't work:\n Type parameter 'T' is declared to extend 'StateStreamableSource<Object?>' producing 'StateStreamableSource<Object?>'.\nThe type 'dynamic' was inferred from:\n Parameter 'create' declared as 'T Function(BuildContext)'\n but argument is 'dynamic Function(BuildContext)'.\n\nConsider passing explicit type argument(s) to the generic.\n\n",
"source": "dart",
"startLineNumber": 13,
"startColumn": 13,
"endLineNumber": 13,
"endColumn": 25
}][{
"resource": "/d:/My Programs/learn_dart/weather_bloc/lib/main.dart",
"owner": "_generated_diagnostic_collection_name_#1",
"code": {
"value": "undefined_method",
"target": {
"$mid": 1,
"external": "https://dart.dev/diagnostics/undefined_method",
"path": "/diagnostics/undefined_method",
"scheme": "https",
"authority": "dart.dev"
}
},
"severity": 8,
"message": "The method 'WeatherCubit' isn't defined for the type 'MyApp'.\nTry correcting the name to the name of an existing method, or defining a method named 'WeatherCubit'.",
"source": "dart",
"startLineNumber": 14,
"startColumn": 30,
"endLineNumber": 14,
"endColumn": 42
}]能给我一点提示吗?
发布于 2022-05-01 20:37:30
从你提供的日志
方法'WeatherCubit‘不是为’MyApp‘类型定义的。\n尝试将名称更正为现有方法的名称,或者定义一个名为'WeatherCubit’的方法。
您忘了导入带有WeatherCubit定义的文件。
https://stackoverflow.com/questions/71987668
复制相似问题