我使用 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/