如何在Flutter应用中使用SOLID原理实现链接到提供者的API调用?

问题描述 投票:0回答:1

我正在尝试重构Flutter天气应用程序。

它最终调用API以位置作为参数提供天气数据。

目前,我有:

  • 与我使用的API给出的JSON响应相对应的WeatherJSONModel.dart。
  • 一个WeatherAPI.dart文件,该文件设法使用参数调用API,并将JSON响应解析为上述模型。
  • 一个WeatherModel.dart,它是应用程序显示的数据的模型。
  • [WeatherProvider(扩展ChangeNotifier),它将API返回的WeatherJSONModel转换为WeatherModel,然后可用于该应用程序。

我非常怀疑这是最有效的方法,但是找不到如何正确实现我的呼叫。

应该将更多的APICallClass放入ResponseHandlerClass还是ProviderClass吗?

谢谢!

TLDR;如何遵循SOLID原则来实现API调用和JSON解析?

json flutter solid-principles flutter-provider
1个回答
0
投票

在我看来,有关此主题的最佳教程之一(在我看来可以找到:

https://github.com/ResoCoder/flutter-tdd-clean-architecture-course

还有一个written series和一个7小时的YouTube Tutorial

这是架构师建议:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.