Skip to content

Commit 7de6eea

Browse files
committed
🎨 Split selected animated backdrop widget.
1 parent 9308a40 commit 7de6eea

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

lib/src/widget/asset_picker.dart

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,38 @@ class AssetPicker extends StatelessWidget {
583583
);
584584
}
585585

586+
/// Animated backdrop widget for items.
587+
/// 部件选中时的动画遮罩部件
588+
Widget _selectedBackdrop(
589+
BuildContext context,
590+
int index,
591+
AssetEntity asset,
592+
) {
593+
return Selector<AssetPickerProvider, List<AssetEntity>>(
594+
selector: (BuildContext _, AssetPickerProvider provider) =>
595+
provider.selectedAssets,
596+
builder: (BuildContext _, List<AssetEntity> selectedAssets, Widget __) {
597+
final bool selected = selectedAssets.contains(asset);
598+
return Positioned.fill(
599+
child: GestureDetector(
600+
onTap: () {
601+
AssetPickerViewer.pushToViewer(
602+
context,
603+
currentIndex: index,
604+
assets: provider.currentAssets,
605+
themeData: theme,
606+
);
607+
},
608+
child: AnimatedContainer(
609+
duration: switchingPathDuration,
610+
color: selected ? Colors.black45 : Colors.black.withOpacity(0.1),
611+
),
612+
), // 点击预览同目录下所有资源
613+
);
614+
},
615+
);
616+
}
617+
586618
/// Indicator for asset selected status.
587619
/// 资源是否已选的指示器
588620
Widget _selectIndicator(
@@ -698,25 +730,8 @@ class AssetPicker extends StatelessWidget {
698730
return Stack(
699731
children: <Widget>[
700732
builder,
701-
Positioned.fill(
702-
child: GestureDetector(
703-
onTap: () {
704-
AssetPickerViewer.pushToViewer(
705-
context,
706-
currentIndex: index,
707-
assets: provider.currentAssets,
708-
themeData: theme,
709-
);
710-
},
711-
child: AnimatedContainer(
712-
duration: switchingPathDuration,
713-
color: selected
714-
? Colors.black45
715-
: Colors.black.withOpacity(0.1),
716-
),
717-
), // 点击预览同目录下所有资源
718-
),
719-
_selectIndicator(asset, provider.selectedAssets),
733+
_selectedBackdrop(context, index, asset),
734+
_selectIndicator(asset),
720735
],
721736
);
722737
},

0 commit comments

Comments
 (0)