rrousselGit / riverpod

A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
https://riverpod.dev
MIT License
5.82k stars 888 forks source link

[riverpod_lint] avoid_manual_providers_as_generated_provider_dependency #3470

Open SheepYang1993 opened 1 month ago

SheepYang1993 commented 1 month ago

Describe the bug vipTypeListInfoProvider.notifierwill show lint avoid_manual_providers_as_generated_provider_dependency

To Reproduce This is my code

import 'package:qlzm_color_flutter/model/response/vip_type_list_response.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../network/api/pay_api.dart';
import '../util/app_util.dart';
import '../util/storage_util.dart';

part 'vip_riverpod.g.dart';

@riverpod
Future<void> refreshVipTypeList(RefreshVipTypeListRef ref) async {
  VipTypeListResponse response = await PayApi.getVipTypeList();
  List<VipTypeListData>? vipTypeList = response.data;
  await StorageUtil().write(StorageUtil.keyVipTypeList, vipTypeList);
  ref.read(vipTypeListInfoProvider.notifier).set(vipTypeList);
}

@Riverpod(keepAlive: true)
class VipTypeListInfo extends _$VipTypeListInfo {
  @override
  List<VipTypeListData>? build() {
    List<VipTypeListData>? vipTypeList = StorageUtil()
        .read<List<VipTypeListData>>(StorageUtil.keyVipTypeList,
            fromJson: (jsonList) {
      if (jsonList is List) {
        return jsonList.map((json) {
          return VipTypeListData.fromJson(json);
        }).toList();
      }
      return <VipTypeListData>[];
    });
    return vipTypeList;
  }

  set(List<VipTypeListData>? vipTypeList) {
    state = vipTypeList;
    AppUtil().saveVipTypeList(vipTypeList);
  }
}

Expected behavior I'm not sure if it's a code issue or a Lint error

rrousselGit commented 1 month ago

Generally, it's just the IDE that's out of date. You're most likely facing https://github.com/dart-lang/sdk/issues/54113.

Does the warning disappear if you restart the IDE or open the generated file?

SheepYang1993 commented 1 month ago

Generally, it's just the IDE that's out of date. You're most likely facing dart-lang/sdk#54113.

Does the warning disappear if you restart the IDE or open the generated file?

Restart the IDE or reopen the generated file, lint will not disappear.

When I added a parameter and run build_runner build, Lint disappeared.

@riverpod
Future<void> refreshVipTypeList(
  RefreshVipTypeListRef ref, {
  bool showLoading = false,
})

My Flutter version is 3.19.3 flutter_riverpod: 2.5.1 riverpod_annotation: 2.3.5 riverpod_generator: 2.4.0 riverpod_lint: 2.3.10

I haven't tried the method of upgrading IDE and Flutter yet, but I will try it out in the future.