pathEntityWidget method

  1. @override
Widget pathEntityWidget({
  1. required BuildContext context,
  2. required Map<AssetPathEntity, Uint8List?> list,
  3. required int index,
  4. bool isAudio = false,
})
override

Item widgets for path entity selector. 路径单独条目选择组件

Implementation

@override
Widget pathEntityWidget({
  required BuildContext context,
  required Map<AssetPathEntity, Uint8List?> list,
  required int index,
  bool isAudio = false,
}) {
  final AssetPathEntity pathEntity = list.keys.elementAt(index);
  final Uint8List? data = list.values.elementAt(index);

  Widget builder() {
    if (isAudio) {
      return ColoredBox(
        color: theme.colorScheme.primary.withOpacity(0.12),
        child: const Center(child: Icon(Icons.audiotrack)),
      );
    }

    // The reason that the `thumbData` should be checked at here to see if it
    // is null is that even the image file is not exist, the `File` can still
    // returned as it exist, which will cause the thumb bytes return null.
    //
    // 此处需要检查缩略图为空的原因是:尽管文件可能已经被删除,
    // 但通过 `File` 读取的文件对象仍然存在,使得返回的数据为空。
    if (data != null) {
      return Image.memory(data, fit: BoxFit.cover);
    }
    return ColoredBox(color: theme.colorScheme.primary.withOpacity(0.12));
  }

  return Material(
    type: MaterialType.transparency,
    child: InkWell(
      splashFactory: InkSplash.splashFactory,
      onTap: () {
        provider.switchPath(pathEntity);
        gridScrollController.jumpTo(0);
      },
      child: SizedBox(
        height: isAppleOS ? 64 : 52,
        child: Row(
          children: <Widget>[
            RepaintBoundary(
              child: AspectRatio(aspectRatio: 1, child: builder()),
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsetsDirectional.only(
                  start: 15,
                  end: 20,
                ),
                child: Row(
                  children: <Widget>[
                    Flexible(
                      child: Padding(
                        padding: const EdgeInsetsDirectional.only(end: 10),
                        child: ScaleText(
                          isPermissionLimited && pathEntity.isAll
                              ? Constants.textDelegate.accessiblePathName
                              : pathEntity.name,
                          style: const TextStyle(fontSize: 17),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ),
                    ScaleText(
                      '(${pathEntity.assetCount})',
                      style: TextStyle(
                        color: theme.textTheme.caption?.color,
                        fontSize: 17,
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ],
                ),
              ),
            ),
            Selector<DefaultAssetPickerProvider, AssetPathEntity?>(
              selector: (_, DefaultAssetPickerProvider p) =>
                  p.currentPathEntity,
              builder: (_, AssetPathEntity? currentPathEntity, __) {
                if (currentPathEntity == pathEntity) {
                  return AspectRatio(
                    aspectRatio: 1,
                    child: Icon(Icons.check, color: themeColor, size: 26),
                  );
                }
                return const SizedBox.shrink();
              },
            ),
          ],
        ),
      ),
    ),
  );
}