onAssetsChanged method

  1. @override
Future<void> onAssetsChanged(
  1. MethodCall call,
  2. StateSetter setState
)
override

Called when assets changed and obtained notifications from the OS. 系统发出资源变更的通知时调用的方法

Implementation

@override
Future<void> onAssetsChanged(MethodCall call, StateSetter setState) async {
  if (!isPermissionLimited) {
    return;
  }
  final AssetPathEntity? currentPathEntity = provider.currentPath;
  if (call.arguments is Map) {
    final Map<dynamic, dynamic> arguments =
        call.arguments as Map<dynamic, dynamic>;
    if (arguments['newCount'] == 0) {
      provider
        ..currentAssets = <AssetEntity>[]
        ..currentPath = null
        ..hasAssetsToDisplay = false
        ..isAssetsEmpty = true;
      return;
    }
    if (currentPathEntity == null) {
      await provider.getPaths();
    }
  }
  if (currentPathEntity != null) {
    final AssetPathEntity newPath =
        await currentPathEntity.obtainForNewProperties();
    provider
      ..currentPath = newPath
      ..hasAssetsToDisplay = newPath.assetCount != 0
      ..isAssetsEmpty = newPath.assetCount == 0
      ..totalAssetsCount = newPath.assetCount;
    isSwitchingPath.value = false;
    if (newPath.isAll) {
      await provider.getAssetsFromCurrentPath();
    }
  }
}