flutter 中最新的 RiverPod 生成器如何与 MVC 集成

How does the latest RiverPod generator in flutter integrate with MVC

提问人:laterday 提问时间:11/14/2023 最后编辑:laterday 更新时间:11/14/2023 访问量:30

问:

例如:我有 A 页面、A 控制器,在 A 控制器中存储了大量数据和更新数据的方法(字符串布尔模型类,更新字符串更新模型类来获取数据),这样的结构用最新的语法生成器应该如何实现

class AController extends GetxController {
  // -------------------------------------------------------------------------------------------- > State & Controller
  static EngineerRepairController get to => Get.find();

  CallDetailModel callDetailData = CallDetailModel();
  List<FaultTypeListModel> faultTypeList = [];

  @override
  void onInit() async {
    super.onInit();
    handleGetCallDetail();
  }

  // -------------------------------------------------------------------------------------------- > Updater
  void updateCallDetail(CallDetailModel val) => callDetailData = val;
  void updateFaultType(List<FaultTypeListModel> val) => faultTypeList = val;

  // -------------------------------------------------------------------------------------------- > Action
  Future handleGetCallDetail() async {
    try {
      Map<String, dynamic> params = {'id': Get.arguments['id']};
      dynamic res = await HttpService.to.get(EngineerRepairApis.getCallDetailDataApi, params: params);
      updateCallDetail(CallDetailModel.fromJson(res));
      update();
    } catch (e) {
    }
  }}

This is how I define and update data in getx. Now I'm trying to switch to riverpod. How do I implement this in the latest riverpod generator
Flutter Dart 模型-视图-控制器 RiverPod

评论


答: 暂无答案