android - 在 flutter 中使用 MVP 架构的 Chopper

标签 android ios flutter mvp chopper

我使用 Chopper 来调用 api,我想得到结果 json,
这是我要调用的 API
[ https://api.jsonbin.io/b/5e1219328d761771cc8b9394]

想问一下这种问题怎么解决

Unhandled Exception: NoSuchMethodError: The method 'inheritFromWidgetOfExactType' was called on null.



我的课是
part 'APIService.chopper.dart';
@ChopperApi(baseUrl:"/b/")
abstract class ApiService extends ChopperService {

  @Get(path: "5e1219328d761771cc8b9394")
  Future<Response> getPost();


  static ApiService create() {
    final client = ChopperClient(
        baseUrl: "https://api.jsonbin.io/",
        services: [_$ApiService(),],
        converter: JsonConverter());
    return _$ApiService(client);
  }
}

然后我调用这个函数来测试 Chooper
 void testAPI() async
  {
    final response  = await Provider.of<ApiService>(context).getPost();
    print(response.body);
  }

但我有一个问题,我不能调用 testAPI
你能帮助我吗 ?

提前谢谢你,对不起语法顺便说一句,

最佳答案

void testAPI() async
  {
    final response  = await ApiService.create().getPost();
    print(response.body);
  }

这是我的问题的正确答案

关于android - 在 flutter 中使用 MVP 架构的 Chopper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60260857/

相关文章:

ios - 单击选项卡时,选项卡栏 Controller 不显示 XIB UIViewController

json - 与颜色相关的 flutter 图像

dart - 如何从 Flutter(Dart) 中的另一个类调用方法?

android - 外部库和 Android list

android - 在 Android 中拉动刷新 GridView

ios - 取 NSString 占位符的 C 函数宏

flutter - 我可以将对象作为参数传递给小部件吗

android - 在 Android 设备上调试 Web 请求

android - sqlite 中的图像巨大

ios - Root View 未显示在屏幕中间