pathEntityWidget method
Widget
pathEntityWidget({
- required BuildContext context,
- required Map<
AssetPathEntity, Uint8List?> list, - required int index,
- 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));
}
final String pathName =
pathNameBuilder?.call(pathEntity) ?? pathEntity.name;
final String name = isPermissionLimited && pathEntity.isAll
? textDelegate.accessiblePathName
: pathName;
final String semanticsName = isPermissionLimited && pathEntity.isAll
? semanticsTextDelegate.accessiblePathName
: pathName;
final String semanticsCount = '${pathEntity.assetCount}';
return Selector<DefaultAssetPickerProvider, AssetPathEntity?>(
selector: (_, DefaultAssetPickerProvider p) => p.currentPath,
builder: (_, AssetPathEntity? currentPathEntity, __) {
final bool isSelected = currentPathEntity == pathEntity;
return Semantics(
label: '$semanticsName, '
'${semanticsTextDelegate.sUnitAssetCountLabel}: '
'$semanticsCount',
selected: isSelected,
onTapHint: semanticsTextDelegate.sActionSwitchPathLabel,
button: false,
child: Material(
type: MaterialType.transparency,
child: InkWell(
splashFactory: InkSplash.splashFactory,
onTap: () {
Feedback.forTap(context);
context
.read<DefaultAssetPickerProvider>()
.switchPath(pathEntity);
isSwitchingPath.value = false;
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: ExcludeSemantics(
child: Row(
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsetsDirectional.only(
end: 10,
),
child: ScaleText(
name,
style: const TextStyle(fontSize: 17),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
ScaleText(
'($semanticsCount)',
style: TextStyle(
color: theme.textTheme.caption?.color,
fontSize: 17,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
),
if (isSelected)
AspectRatio(
aspectRatio: 1,
child: Icon(Icons.check, color: themeColor, size: 26),
),
],
),
),
),
),
);
},
);
}