简体   繁体   English

Flutter 布洛克 & 肘

[英]Flutter Bloc & Cubit

I am following the tutorial here: https://resocoder.com/2020/08/04/flutter-bloc-cubit-tutorial/ .我正在关注这里的教程: https://resocoder.com/2020/08/04/flutter-bloc-cubit-tutorial/

When I reached the "Building with Cubit" part and in the main.dart , I have the following issue:当我到达“使用 Cubit 构建”部分和main.dart时,出现以下问题:

在此处输入图像描述

The errors I have:我的错误:

[{
    "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
}]

Can give me some hints on this?可以给我一些提示吗?

From the log you provided从您提供的日志

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'.未为类型“MyApp”定义方法“WeatherCubit”。\n请尝试将名称更正为现有方法的名称,或定义一个名为“WeatherCubit”的方法。

You forgot to import file with WeatherCubit definition.您忘记导入带有WeatherCubit定义的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM