Created
September 6, 2023 03:55
-
-
Save Heilum/31abcdace37edc2dd5ce4b30ff0df6ee to your computer and use it in GitHub Desktop.
Using wechat_assets_picker package to pick image/video, and live record simultaneously
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:wechat_assets_picker/wechat_assets_picker.dart'; | |
import 'package:wechat_camera_picker/wechat_camera_picker.dart'; | |
Future<void> showAssetsPicker( | |
BuildContext context, | |
bool forVideo, | |
int maxCount, { | |
required Function(BuildContext, List<AssetEntity>? result) handleResult, | |
}) async { | |
Color themeColor = Colors.red; | |
var r = await AssetPicker.pickAssets( | |
context, | |
pickerConfig: AssetPickerConfig( | |
themeColor: themeColor, | |
maxAssets: maxCount, | |
requestType: forVideo ? RequestType.video : RequestType.image, | |
specialItemPosition: SpecialItemPosition.prepend, | |
specialPickerType: SpecialPickerType.noPreview, | |
specialItemBuilder: ( | |
BuildContext context, | |
AssetPathEntity? path, | |
int length, | |
) { | |
if (path?.isAll != true) { | |
return null; | |
} | |
return Semantics( | |
button: true, | |
child: GestureDetector( | |
behavior: HitTestBehavior.opaque, | |
onTap: () async { | |
Feedback.forTap(context); | |
final AssetEntity? result = | |
await CameraPicker.pickFromCamera( | |
context, | |
pickerConfig: CameraPickerConfig(enableRecording: forVideo,theme:CameraPicker.themeData(themeColor)), | |
); | |
if (result != null) { | |
//pop(context); | |
if (context.mounted) { | |
Navigator.pop(context); | |
handleResult(context, [result]); | |
} | |
} else { | |
if (context.mounted) { | |
handleResult(context, null); | |
} | |
} | |
}, | |
child: const Center( | |
child: Icon(Icons.camera_enhance, size: 42.0), | |
), | |
), | |
); | |
}, | |
), | |
); | |
handleResult(context, r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment