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));
}
return Material(
type: MaterialType.transparency,
child: InkWell(
splashFactory: InkSplash.splashFactory,
onTap: () {
provider.switchPath(pathEntity);
gridScrollController.jumpTo(0);
},
child: SizedBox(
height: isAppleOS ? 64.0 : 52.0,
child: Row(
children: <Widget>[
RepaintBoundary(
child: AspectRatio(aspectRatio: 1.0, child: builder()),
),
Expanded(
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: 15.0,
end: 20.0,
),
child: Row(
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsetsDirectional.only(end: 10.0),
child: Text(
pathEntity.name,
style: const TextStyle(fontSize: 18.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
Text(
'(${pathEntity.assetCount})',
style: TextStyle(
color: theme.textTheme.caption?.color,
fontSize: 18.0,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
Selector<DefaultAssetPickerProvider, AssetPathEntity?>(
selector: (_, DefaultAssetPickerProvider p) =>
p.currentPathEntity,
builder: (_, AssetPathEntity? currentPathEntity, __) {
if (currentPathEntity == pathEntity) {
return AspectRatio(
aspectRatio: 1.0,
child: Icon(Icons.check, color: themeColor, size: 26.0),
);
}
return const SizedBox.shrink();
},
),
],
),
),
),
);
}