Skip to content

Commit d683fcf

Browse files
committed
🚸 Add cameraAndStay pick method
1 parent 4676257 commit d683fcf

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

example/lib/constants/picker_method.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,47 @@ class PickMethod {
9999
);
100100
}
101101

102+
factory PickMethod.cameraAndStay({required int maxAssetsCount}) {
103+
return PickMethod(
104+
icon: '📸',
105+
name: 'Pick from camera and stay',
106+
description: 'Take a photo or video with the camera picker, '
107+
'select the result and stay in the entities list.',
108+
method: (BuildContext context, List<AssetEntity> assets) {
109+
return AssetPicker.pickAssets(
110+
context,
111+
maxAssets: maxAssetsCount,
112+
selectedAssets: assets,
113+
requestType: RequestType.common,
114+
specialItemPosition: SpecialItemPosition.prepend,
115+
specialItemBuilder: (BuildContext context) {
116+
return GestureDetector(
117+
behavior: HitTestBehavior.opaque,
118+
onTap: () async {
119+
final AssetEntity? result = await CameraPicker.pickFromCamera(
120+
context,
121+
enableRecording: true,
122+
);
123+
if (result != null) {
124+
final AssetPicker<AssetEntity, AssetPathEntity> picker =
125+
context.findAncestorWidgetOfExactType()!;
126+
final DefaultAssetPickerProvider p =
127+
picker.builder.provider as DefaultAssetPickerProvider;
128+
await p.currentPathEntity!.refreshPathProperties();
129+
await p.switchPath(p.currentPathEntity!);
130+
p.selectAsset(result);
131+
}
132+
},
133+
child: const Center(
134+
child: Icon(Icons.camera_enhance, size: 42.0),
135+
),
136+
);
137+
},
138+
);
139+
},
140+
);
141+
}
142+
102143
factory PickMethod.common(int maxAssetsCount) {
103144
return PickMethod(
104145
icon: '📹',

example/lib/pages/multi_assets_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class _MultiAssetsPageState extends State<MultiAssetsPage>
3737
handleResult: (BuildContext context, AssetEntity result) =>
3838
Navigator.of(context).pop(<AssetEntity>[...assets, result]),
3939
),
40+
PickMethod.cameraAndStay(maxAssetsCount: maxAssetsCount),
4041
PickMethod.common(maxAssetsCount),
4142
PickMethod.threeItemsGrid(maxAssetsCount),
4243
PickMethod.customFilterOptions(maxAssetsCount),

example/lib/pages/single_assets_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class _SingleAssetPageState extends State<SingleAssetPage>
3737
handleResult: (BuildContext context, AssetEntity result) =>
3838
Navigator.of(context).pop(<AssetEntity>[result]),
3939
),
40+
PickMethod.cameraAndStay(maxAssetsCount: maxAssetsCount),
4041
PickMethod.common(maxAssetsCount),
4142
PickMethod.threeItemsGrid(maxAssetsCount),
4243
PickMethod.customFilterOptions(maxAssetsCount),

0 commit comments

Comments
 (0)