selectIndicator method
Indicator for assets selected status. 资源是否已选的指示器
Implementation
@override
Widget selectIndicator(BuildContext context, AssetEntity asset) {
final Duration duration = switchingPathDuration * 0.75;
return Selector<DefaultAssetPickerProvider, String>(
selector: (_, DefaultAssetPickerProvider p) => p.selectedDescriptions,
builder: (BuildContext context, _, __) {
final List<AssetEntity> selectedAssets =
context.select<DefaultAssetPickerProvider, List<AssetEntity>>(
(DefaultAssetPickerProvider p) => p.selectedAssets,
);
final bool selected = selectedAssets.contains(asset);
final double indicatorSize =
context.mediaQuery.size.width / gridCount / 3;
final Widget innerSelector = AnimatedContainer(
duration: duration,
width: indicatorSize / (isAppleOS ? 1.25 : 1.5),
height: indicatorSize / (isAppleOS ? 1.25 : 1.5),
decoration: BoxDecoration(
border:
!selected ? Border.all(color: Colors.white, width: 2) : null,
color: selected ? themeColor : null,
shape: BoxShape.circle,
),
child: AnimatedSwitcher(
duration: duration,
reverseDuration: duration,
child: selected
? const Icon(Icons.check, size: 18)
: const SizedBox.shrink(),
),
);
final GestureDetector selectorWidget = GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () async {
final bool? selectPredicateResult = await selectPredicate?.call(
context,
asset,
selected,
);
if (selectPredicateResult == false) {
return;
}
if (selected) {
provider.unSelectAsset(asset);
return;
}
if (isSingleAssetMode) {
provider.selectedAssets.clear();
}
provider.selectAsset(asset);
if (isSingleAssetMode && !isPreviewEnabled) {
Navigator.of(context).maybePop(provider.selectedAssets);
}
},
child: Container(
margin: EdgeInsets.all(
context.mediaQuery.size.width / gridCount / 12,
),
width: isPreviewEnabled ? indicatorSize : null,
height: isPreviewEnabled ? indicatorSize : null,
alignment: AlignmentDirectional.topEnd,
child: (!isPreviewEnabled && isSingleAssetMode && !selected)
? const SizedBox.shrink()
: innerSelector,
),
);
if (isPreviewEnabled) {
return PositionedDirectional(
top: 0,
end: 0,
child: selectorWidget,
);
}
return selectorWidget;
},
);
}